Django PasswordChangeForm 中的自动对焦字段是什么?
What is the autofocus field in Django PasswordChangeForm?
我正在查看 Django 文档,发现我没有得到这行代码,特别是自动对焦部分
class PasswordChangeForm(SetPasswordForm):
"""
A form that lets a user change their password by entering their old
password.
"""
error_messages = {
**SetPasswordForm.error_messages,
'password_incorrect': _("Your old password was entered incorrectly. Please enter it again."),
}
old_password = forms.CharField(
label=_("Old password"),
strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'current-password', 'autofocus': True}),
)
field_order = ['old_password', 'new_password1', 'new_password2']
def clean_old_password(self):
"""
Validate that the old_password field is correct.
"""
old_password = self.cleaned_data["old_password"]
if not self.user.check_password(old_password):
raise ValidationError(
self.error_messages['password_incorrect'],
code='password_incorrect',
)
return old_password
在 widget=forms.PasswordInput(attrs={'autocomplete': 'current-password', 'autofocus': True}) 部分,我不明白自动对焦字段是什么是,当它说它是真的时它做了什么。
这样做的目的是什么??
autofocus: True 使“old_password”输入字段在页面加载时自动获得焦点。就这么简单
我正在查看 Django 文档,发现我没有得到这行代码,特别是自动对焦部分
class PasswordChangeForm(SetPasswordForm):
"""
A form that lets a user change their password by entering their old
password.
"""
error_messages = {
**SetPasswordForm.error_messages,
'password_incorrect': _("Your old password was entered incorrectly. Please enter it again."),
}
old_password = forms.CharField(
label=_("Old password"),
strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'current-password', 'autofocus': True}),
)
field_order = ['old_password', 'new_password1', 'new_password2']
def clean_old_password(self):
"""
Validate that the old_password field is correct.
"""
old_password = self.cleaned_data["old_password"]
if not self.user.check_password(old_password):
raise ValidationError(
self.error_messages['password_incorrect'],
code='password_incorrect',
)
return old_password
在 widget=forms.PasswordInput(attrs={'autocomplete': 'current-password', 'autofocus': True}) 部分,我不明白自动对焦字段是什么是,当它说它是真的时它做了什么。
这样做的目的是什么??
autofocus: True 使“old_password”输入字段在页面加载时自动获得焦点。就这么简单