0

I have a new page with simple_form_for elements as shown below

<%= simple_form_for @invoice, :html => { :class => 'form-horizontal' } do |f| %>
  <%= render "shared/error_messages", :target => @invoice %>

  <%= f.association :customer %>
  <%= f.input :invoice_date, as: :string, input_html: { class: "datepicker"} %>
<% end %>

I am trying to incorporate calendar element into the form above, from the unicorm admin template theme. My Assets file contains bootstrap-datepicker.js which I am trying to incorporate in the form above. Whenever I add an extra HTML attribute to invoice_date input, I get a syntaxt error.

I tried this

<%= f.input :invoice_date, as: :string, input_html: { class: "datepicker", data-date-format="dd-mm-yyyy"} %>

Which yielded an error. How do i incorporate the calendar function to invoice_date above from bootstrap-datepicker.js in my template?

2 Answers 2

1

You have an erroneous = sign in your line of code. Also, since you've got a symbol key in your hash, which contains dashes (data-date-format), you'll need to use the older style 'hashrocket' symbol formatting.

You could do this:

<%= f.input :invoice_date, as: :string, input_html: { class: "datepicker", :'data-date-format' => "dd-mm-yyyy"} %>

I'm not a fan of mixing the two styles, so you could also do this:

<%= f.input :invoice_date, :as => :string, :input_html => { :class => "datepicker", :'data-date-format' => "dd-mm-yyyy"} %>
Sign up to request clarification or add additional context in comments.

Comments

0

I figured out what the problem was, I had not added twitter bootstrap to my project

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.