3

I can't get the id to work in simple form on a button, I've tried

this

= f.button, :input_html => { :id => 'my_id' }
= f.button, :input_html => { :id => 'my_id' }, :submit

and this

= f.button, html: { id: :edit_account } 
= f.button, html: { id: :edit_account } :submit

What's the proper way of doing it?

Community
  • 1
  • 1
Gaston
  • 1,004
  • 1
  • 9
  • 23

2 Answers2

4

= f.button :submit, id: "whatever"

If you look at the documentation, it accepts an optional string and an options hash (for class or id). Internally, it simply calls the submit_tag helper and that's why it's different from the input helper where you pass any HTML attributes in the input_html hash.

Teoulas
  • 2,943
  • 22
  • 27
1

Try = f.button :submit, input_html: { id: 'edit_account' }

From docs:

If you want to pass the same options to all inputs in the form (for example, a default class), you can use the :defaults option in simple_form_for. Specific options in input call will overwrite the defaults:

<%= simple_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f| %>
  <%= f.input :username, input_html: { class: 'special' } %>
  <%= f.input :password, input_html: { maxlength: 20 } %>
  <%= f.input :remember_me, input_html: { value: '1' } %>
  <%= f.button :submit %>
<% end %>

Since Simple Form generates a wrapper div around your label and input by default, you can pass any html attribute to that wrapper as well using the :wrapper_html option, like so:

<%= simple_form_for @user do |f| %>
  <%= f.input :username, wrapper_html: { class: 'username' } %>
  <%= f.input :password, wrapper_html: { id: 'password' } %>
  <%= f.input :remember_me, wrapper_html: { class: 'options' } %>
  <%= f.button :submit %>
<% end %>
LucasM
  • 373
  • 2
  • 5