Using datepicker within haml

2019-08-24 05:24发布

问题:

I am sorta new to using datepicker within haml and was hoping to get some guidance. I have included a javascript with a datepicker within my main.html along with two date fields. Unfortunately, when I try to test the following code I get nothing. Any idea what I might be overlooking? Any help will be greatly appricated.

#content

%h3
  Please enter the following information:
=form('/search', :post)
=input(:id, :report_id, class: "formbox")
=input(:date, :start_date, class: "formbox")
=input(:date, :end_date, class: "formbox")
=submit('Submit', class: "button")

:javascript
  $(function() {
    $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});
  });

回答1:

In HAML, the way you indent is key to your code working correctly. You need to change your indentation as follows:

%h3
  Please enter the following information:
= form('/search', :post)
  = input(:id, :report_id, class: "formbox")
  = input(:date, :start_date, class: "formbox")
  = input(:date, :end_date, class: "formbox")
  = submit('Submit', class: "button")

:javascript
  $(function() {
    $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});
  });