Convert TwoFactorForm to gov uk frontend

This commit is contained in:
Pea Tyczynska
2020-08-03 18:12:52 +01:00
committed by Tom Byers
parent be7d4891ae
commit ebd8588c03
4 changed files with 18 additions and 17 deletions

View File

@@ -310,7 +310,7 @@ class GovukSearchField(SearchField):
return govuk_field_widget(self, field, type="search", param_extensions=params, **kwargs) return govuk_field_widget(self, field, type="search", param_extensions=params, **kwargs)
class SMSCode(StringField): class SMSCode(GovukTextInputField):
validators = [ validators = [
DataRequired(message='Cannot be empty'), DataRequired(message='Cannot be empty'),
Regexp(regex=r'^\d+$', message='Numbers only'), Regexp(regex=r'^\d+$', message='Numbers only'),
@@ -319,7 +319,12 @@ class SMSCode(StringField):
] ]
def __call__(self, **kwargs): def __call__(self, **kwargs):
return super().__call__(type='tel', pattern='[0-9]*', **kwargs) params = {"attributes": {"pattern": "[0-9]*"}}
if "param_extensions" in kwargs:
kwargs["param_extensions"].update(params)
else:
kwargs["param_extensions"] = params
return super().__call__(type='tel', **kwargs)
def process_formdata(self, valuelist): def process_formdata(self, valuelist):
if valuelist: if valuelist:

View File

@@ -16,11 +16,10 @@
<p class="govuk-body">Weve sent you a text message with a security code.</p> <p class="govuk-body">Weve sent you a text message with a security code.</p>
{% call form_wrapper(class="extra-tracking") %} {% call form_wrapper(class="extra-tracking") %}
{{ textbox( {{ form.sms_code(param_extensions={
form.sms_code, "classes": "govuk-input govuk-input--width-5",
width='5em', "attributes": {"data-module": "autofocus"}
autofocus=True }) }}
) }}
{{ page_footer( {{ page_footer(
"Continue", "Continue",
secondary_link=url_for('main.check_and_resend_text_code'), secondary_link=url_for('main.check_and_resend_text_code'),

View File

@@ -21,11 +21,11 @@
Weve sent a security code to your new {{ thing }}. Weve sent a security code to your new {{ thing }}.
</p> </p>
{% call form_wrapper() %} {% call form_wrapper() %}
{{ textbox( {{ form_field(param_extensions={
form_field, "classes": "govuk-input govuk-input--width-5",
width='5em', "attributes": {"data-module": "autofocus"}
autofocus=True }) }}
) }}
{{ page_footer('Confirm') }} {{ page_footer('Confirm') }}
{% endcall %} {% endcall %}
</div> </div>

View File

@@ -9,7 +9,6 @@ from itsdangerous import SignatureExpired
from notifications_python_client.errors import HTTPError from notifications_python_client.errors import HTTPError
from app.main.views.verify import activate_user from app.main.views.verify import activate_user
from tests.conftest import normalize_spaces
def test_should_return_verify_template( def test_should_return_verify_template(
@@ -96,10 +95,8 @@ def test_should_return_200_when_sms_code_is_wrong(
_expected_status=200, _expected_status=200,
) )
assert len(page.select('.error-message')) == 1 assert len(page.select('.govuk-error-message')) == 1
assert normalize_spaces(page.select_one('.error-message').text) == ( assert 'Code not found' in page.select_one('.govuk-error-message').text
'Code not found'
)
def test_verify_email_redirects_to_verify_if_token_valid( def test_verify_email_redirects_to_verify_if_token_valid(