Rails 4 simple_form disable form-level auto-completion

I have an autocomplete setting in my application, and during testing, I noticed that it unexpectedly didn’t work just a few minutes before. The application returned a pg error stating that employee_id was null .

I realized that the browsers' own autocomplete told me the value, and therefore js did not insert the id value into the hidden field.

When I check the Mozilla documentation, I see that they recommend disabling auto-completion at the form level. I am using simple_form but cannot figure out how to do this.

 <form name="form1" id="form1" method="post" autocomplete="off" 
+7
ruby-on-rails simple-form
source share
2 answers

Just pass the autocomplete parameter to the hash :html :

 <%= simple_form_for @user, html: { autocomplete: 'off' } do |f| %> <%= f.input :country, as: :string %> <% end %> 
+23
source share

If you want to disable it for only one or several attributes instead of the entire form, you can use the " input_html " option, for example:

 <%= simple_form_for(@user, url: @form_url) do |f| %> ... <%= f.input :password, input_html: { autocomplete: 'off' } %> <%= f.submit %> <% end %> 
+8
source share

All Articles