javascriptruby-on-railspickadate

Using pickadate.js with a standard rails form


I'm trying to add pickadate.js to my project for the first time. I'm hitting some snags with trying to get the functionality working. Here is what I'm currently working with.

Datepicker.js

var $input = $('.start-datepicker').pickadate()

var picker = $input.pickadate('picker')

picker.open()

Form.html.erb

<div>
   <%= form.text_field :start_at, class: "new-assignment-form__input start-datepicker", placeholder: "Start Time" %>
</div>

That basically it. The action I'm going for is if a user tries to use that field it will pop open the date picker. It seemed from the docs that this is all that was needed but clearly I'm missing something because nothing happens with the current setup. Thanks for the help!


Solution

  • Okay based on our discussion, it looks like this selector:

    $('.start-datepicker')
    

    is not selecting anything. Double check to make sure that you have an element defined with a class of "start-datepicker".