I have setup autocomplete in my application and I noticed during testing that it suddenly failed having just been working just moments before. The application returned a pg error claiming that the employee_id value was null.
I realized that the browsers native autocomplete had prompted me with the value and therefore the js
didn't insert the id value into the hidden field.
On checking the Mozilla documentation I see that they recommend turning off autocomplete at the form level. I am using simple_form but can't figure out how to do this.
<form name="form1" id="form1" method="post" autocomplete="off"
Just pass autocomplete
option to the :html
hash:
<%= simple_form_for @user, html: { autocomplete: 'off' } do |f| %>
<%= f.input :country, as: :string %>
<% end %>
If you want to turn it off just for one or more attributes instead of the entire form, you can use the option "input_html", like this:
<%= simple_form_for(@user, url: @form_url) do |f| %>
...
<%= f.input :password, input_html: { autocomplete: 'off' } %>
<%= f.submit %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With