1

I'm using jquery datepciker in a Rails app. I would like to have the date already filled in when the form page loads. So, that the user can leave the date as-is or change it.

I was hoping the datepicker options would let me do that.

I tried this:

    $("#comment_status_date").datepicker({
    dateFormat: 'yy-mm-dd',
    setDate: Date.now
});

But, the date field was empty.

Do I have to do some ruby code in the model or controller? Does datepicker have an option to do this?

Thanks!!

I figured out a way:

<%= f.input :status_date, :as => :string, :label => 'Date', :class => 'calendar hasDatepicker', :input_html => { :value => Date.today.to_s } %>
2
  • Try Date.today , now is for Time.now . Commented Dec 21, 2012 at 16:24
  • Thanks - Date.today worked. But, I put it into the form instead of using datepicker option. Commented Dec 21, 2012 at 16:35

1 Answer 1

1

I figured out a way:

<%= f.input :status_date, :as => :string, :label => 'Date', :class => 'calendar hasDatepicker', :input_html => { :value => Date.today.to_s } %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.