6

So, I have a form that uses 'date-select', which renders three select boxes per used date-select (year, month and day).

Instead I want to use datepicker, and I've followed the instructions here. However, I don't have a clue how to actually implement the datepicker in the form in the view.

I'm using the following line in application.js...

$('.datepicker').datepicker()

...so I guess I need to give the select boxes the class .datepicker?

<%= form_for @project do |f| %>
    <div class="text_field">
        <%= f.label :title%>
        <%= f.text_field :title%>
    </div>
    <div class="text_field">
        <%= f.label :description%>
        <%= f.text_field :description%>
    </div>
    <div class="dropdown">
        <%= f.label :start_date%>
        <%= date_select :start_date, :startdate %>
    </div>
    <div class="dropdown">
        <%= f.label :end_date%>
        <%= date_select :end_date, :enddate%>
    </div>
    <div class="select">
        <%= f.label :title%>
    </div>
    <div class="submit">
        <%= f.submit "Spara" %>
    </div>
<% end %>
1
  • Still nothing for date_field?
    – user4412054
    Jul 8, 2015 at 17:33

1 Answer 1

10

Try :

<%= date_select :start_date, :startdate , :class => 'datepicker' %>

EDIT: I have replicated your code on my machine and found the possible mistakes:

This gem selects the date in a text field, not in a date-select . The input should be text_field and it looks like this:

<%= f.text_field :date, :class => 'datepicker' %>

As described in the gem's install guide , you should be sure to require it both in your application.css and application.js . One more important thing : in your projects.js.coffee make sure that the DOM is loaded , like this :

jQuery ->
  $('.datepicker').datepicker()
3
  • Thanks for the answer. Tried that now but nothing happens. Even more strange is that when I check the source code the class isn't even added to the select box. :/ Feb 5, 2013 at 17:03
  • Make sure all the require commands are there, and wrap your datepicker call with $(function() { ... });
    – mccannf
    Feb 5, 2013 at 19:50
  • 3
    Still nothing for date_field?
    – user4412054
    Jul 8, 2015 at 17:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.