misc: only autofocus username field if login block is first (#61881)
This commit is contained in:
parent
c557ec4db8
commit
f63cafb4b6
|
@ -123,6 +123,7 @@ class LoginPasswordAuthenticator(BaseAuthenticator):
|
|||
form.fields['username'].label = _('Username or email')
|
||||
if app_settings.A2_USERNAME_LABEL:
|
||||
form.fields['username'].label = app_settings.A2_USERNAME_LABEL
|
||||
form.fields['username'].widget.attrs['autofocus'] = not (bool(context.get('block_index')))
|
||||
is_secure = request.is_secure
|
||||
context['submit_name'] = self.submit_name
|
||||
if is_post:
|
||||
|
|
|
@ -366,12 +366,14 @@ def login(request, template_name='authentic2/login.html', redirect_field_name=RE
|
|||
parameters['instance_id'] = instance_id
|
||||
if not authenticator.shown(instance_id=instance_id, ctx=show_ctx):
|
||||
continue
|
||||
context['block_index'] = len(blocks)
|
||||
block = utils_misc.get_authenticator_method(authenticator, 'login', parameters)
|
||||
# update block id in order to separate instances
|
||||
block['id'] = '%s_%s' % (block['id'], instance_id)
|
||||
auth_blocks.append(block)
|
||||
else:
|
||||
if authenticator.shown(ctx=show_ctx):
|
||||
context['block_index'] = len(blocks)
|
||||
auth_blocks.append(
|
||||
utils_misc.get_authenticator_method(authenticator, 'login', parameters)
|
||||
)
|
||||
|
|
|
@ -81,6 +81,17 @@ def test_login_autorun(settings, app, franceconnect):
|
|||
assert response.location == reverse('fc-login-or-link')
|
||||
|
||||
|
||||
def test_login_username_autofocus(settings, app, franceconnect):
|
||||
response = app.get('/login/')
|
||||
assert response.text.index('div id="fc-button"') < response.text.index('name="login-password-submit"')
|
||||
assert response.pyquery('#id_username').attr.autofocus is None
|
||||
|
||||
settings.AUTH_FRONTENDS_KWARGS = {'fc': {'priority': 3}}
|
||||
response = app.get('/login/')
|
||||
assert response.text.index('div id="fc-button"') > response.text.index('name="login-password-submit"')
|
||||
assert response.pyquery('#id_username').attr.autofocus is not None
|
||||
|
||||
|
||||
def test_create(settings, app, franceconnect, hooks, service):
|
||||
# test direct creation
|
||||
set_service(app, service)
|
||||
|
|
Loading…
Reference in New Issue