diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2019-09-02 09:50:56 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-09-02 10:50:56 +0200 |
| commit | 999891bd80b3d02dd916731a7a239e1036174885 (patch) | |
| tree | 5bc06ca2beefc0a3dd022d170b4074514c729be2 | |
| parent | 47f49adc11c0d39be3f41f92becc1f606c49d8ce (diff) | |
Refs #29379 -- Moved autocomplete attribute to UsernameField.
Moving the autocomplete attribute into UsernameField allows this to work
for custom forms making use of UsernameField, removes some duplication
in the code, and keeps consistency with the autocapitalize attribute
that is already defined on UsernameField.
| -rw-r--r-- | django/contrib/auth/forms.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 7fbe674948..a0cfed0995 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -62,9 +62,11 @@ class UsernameField(forms.CharField): return unicodedata.normalize('NFKC', super().to_python(value)) def widget_attrs(self, widget): - attrs = super().widget_attrs(widget) - attrs['autocapitalize'] = 'none' - return attrs + return { + **super().widget_attrs(widget), + 'autocapitalize': 'none', + 'autocomplete': 'username', + } class UserCreationForm(forms.ModelForm): @@ -96,10 +98,7 @@ class UserCreationForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self._meta.model.USERNAME_FIELD in self.fields: - self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({ - 'autocomplete': 'username', - 'autofocus': True, - }) + self.fields[self._meta.model.USERNAME_FIELD].widget.attrs['autofocus'] = True def clean_password2(self): password1 = self.cleaned_data.get("password1") @@ -166,7 +165,7 @@ class AuthenticationForm(forms.Form): Base class for authenticating users. Extend this to get a form that accepts username/password logins. """ - username = UsernameField(widget=forms.TextInput(attrs={'autocomplete': 'username', 'autofocus': True})) + username = UsernameField(widget=forms.TextInput(attrs={'autofocus': True})) password = forms.CharField( label=_("Password"), strip=False, |
