0

I used the script below to try and turn off autocomplete features for all my form data.

$(document).ready(function () { $("input").attr("autocomplete", "off"); }); 

However, chrome still saves the autocomplete data and shows previous entry in my login form. This also happens for IE.

How do I stop it from saving previous entered data/text? How do I prevent saved data entry if the user accepts the browser prompt to save the entered data for next time because it can be a potential security issue like saved passwords on a public computer?

I am using ASP .NET MVC3 with Kendo UI for all my form data.

A sample form data entry looks like this:

<div class="editor-field">
                    @Html.TextBoxFor(model => model.first_name, ViewBag.InactivePatient ? (object)new {@class = "formTextbox k-textbox" , disabled="disabled" } : new {@class = "formTextbox k-textbox"})
                    @Html.ValidationMessageFor(model => model.first_name)
                </div>

Also, I tried manually putting autocomplete=off to each form entry but it led me to more errors and I would not like to have to append autocomplete=off to each entry.

Also, I tried appending new {autocomplete ="off"} to @using (Ajax.BeginForm(null, null, new AjaxOptions { }, new { id = "patientForm" })) but I get an error. So, what I'm asking is I'm not sure how to turn off autocomplete in asp .net forms.

Kala J
  • 2,040
  • 4
  • 45
  • 85
  • Read http://stackoverflow.com/questions/3868299/ and http://css-tricks.com/snippets/html/autocomplete-off/ – Tushar Gupta - curioustushar Nov 13 '13 at 17:55
  • This just tells me which browsers support it. I need help plugging it into my form data in .net. – Kala J Nov 13 '13 at 18:02
  • Doesn't help. Please read my post. – Kala J Nov 13 '13 at 18:08
  • You're saying this failed? `@using (Ajax.BeginForm(null, null, new AjaxOptions { }, new { id = "patientForm", autocomplete = "off" }))`. It's preferable to put the `autocomplete` attribute on the form instead of each input - easier to maintain. – Brett Nov 13 '13 at 20:51
  • Brett, that failed for Chrome's login page. For some reason, it keeps failing on Chrome's login. It seems that Chrome remembers saved password and user and it overrides that autocomplete form. – Kala J Dec 10 '13 at 19:03

1 Answers1

0
  1. Pass model to view with Email and Password properties pre-filled with white spaces.

    new UserEditModel { Email = " ", Password = " "};

  2. Reset corresponding inputs in javascript in this way:

    function resetInputs() {
        $('input[name="Password"]').val('');
        $('input[name="Email"]').focus(function() {
        $(this).val('');
        });
    }
    

Note: the trick is to clear the password input only and place event handler (on focus) on email input so it is cleared only if user starts typing his email. If you clear both inputs at once it won't work.