Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #29379 -- Moved autocomplete attribute to UsernameField. #11623

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions django/contrib/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def to_python(self, value):
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):
Expand Down Expand Up @@ -96,10 +98,7 @@ class Meta:
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")
Expand Down Expand Up @@ -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,
Expand Down