rails 4 simple_form turn off autocomplete at form level

markhorrocks picture markhorrocks · Jul 17, 2013 · Viewed 10k times · Source

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"

Answer

Vasiliy Ermolovich picture Vasiliy Ermolovich · Jul 17, 2013

Just pass autocomplete option to the :html hash:

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