Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 4 simple_form turn off autocomplete at form level

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"
like image 927
markhorrocks Avatar asked Jul 17 '13 15:07

markhorrocks


2 Answers

Just pass autocomplete option to the :html hash:

<%= simple_form_for @user, html: { autocomplete: 'off' } do |f| %>
  <%= f.input :country, as: :string %>
<% end %>
like image 152
Vasiliy Ermolovich Avatar answered Nov 15 '22 21:11

Vasiliy Ermolovich


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 %>
like image 23
Fernando Vieira Avatar answered Nov 15 '22 20:11

Fernando Vieira