Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn autocomplete off with rails form_tag

Tags:

I'm trying to turn autocomplete off in one of my rails forms. Here's what I've tried so far:

# add it at the form level = form_tag admin_sessions_path, autocomplete: "off" do 

That didn't work.

# add it at the element level .panel   = label_tag :email   = email_field_tag :email, params[:email], autocomplete: 'off' 

Neither did that.

# add it to both = form_tag admin_sessions_path, autocomplete: "off" do    # add it at the element level   .panel     = label_tag :email     = email_field_tag :email, params[:email], autocomplete: 'off' 

When I visit my form, my email address and saved password are already filled-in. What am I doing wrong here? I love rails, but it really drives me mad sometimes.

like image 598
stephenmurdoch Avatar asked Jul 16 '14 13:07

stephenmurdoch


People also ask

How do you disable browser autocomplete on web form field?

This can be done in a <form> for a complete form or for specific <input> elements: Add autocomplete="off" onto the <form> element to disable autocomplete for the entire form.

How do I turn off autofill in textbox?

Click the Display tab. Do one of the following: To enable AutoComplete for the text box, select the Enable AutoComplete check box. To disable AutoComplete for the text box, clear the Enable AutoComplete check box.


1 Answers

As of Rails 4+

Disable autocomplete for an entire form with form_tag:

= form_tag admin_sessions_path, html: { autocomplete: "off" } do 

Disable autocomplete for an entire form with form_for:

= form_for @user, html: { autocomplete: "off" } do |f| 

Disable autocomplete for a single form element:

= f.text_field :foo, autocomplete: 'off' 

Hope this helps!

like image 110
Matt Sanders Avatar answered Sep 21 '22 15:09

Matt Sanders