zurik
zurik

Reputation: 513

Multiple HTML Attributes Simple_form_for

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?

Upvotes: 0

Views: 1138

Answers (2)

theTRON
theTRON

Reputation: 9649

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"} %>

Upvotes: 1

zurik
zurik

Reputation: 513

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

Upvotes: 0

Related Questions