0

I'm developing an app in Flask using Bootstrap 3 and WTF Forms. In the profile page, the user can change their name, password, etc.

But when I log in and I ask Firefox to remember my password, the new password field is already filled in on the profile page. Simply adding value=' ' to my form field does not clear the password field of the form.

How do I go about clearing it?

braX
  • 11,506
  • 5
  • 20
  • 33
Qbite
  • 219
  • 5
  • 14

1 Answers1

1

Simply add a autocomplete="off" to your render call for your password field:

{{ form.password(autocomplete="off") }}

Alternately, if you are rendering the form using a macro that just loops over each field in the form, you can use a custom widget:

from wtforms.widgets import Input

class PasswordWidget(Input):
    def __call__(self, *args, **kwargs):
        if "autocomplete" not in kwargs:
            kwargs["autocomplete"] = "off"
        return super(InputWidget, self).__call__(*args, **kwargs)

and then in that particular form you can set the widget explicitly:

class UpdateForm(SomeBaseForm):
    password = StringField("Password", widget=PasswordWidget())
Community
  • 1
  • 1
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
  • [Recent versions of Chrome](http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off) have made this much harder - [this question](http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off) provides some solutions worth considering. – Sean Vieira Oct 06 '14 at 14:07
  • Is there any workaround here, if the user has set Firefox to remember the email / password even though I have set the autocomplete="off"? – lozadaOmr Aug 06 '15 at 16:02