Enable numeric keypad for text message code

If you’re signing in on a phone, it’s easier to type the two factor code
with a numeric keypad. The most reliable way to get the numeric keypad
to show up on multiple devices is:
- `type='tel'` (not `type='number'` because that’s only meant for
  numbers, not string of digits, ie `01234` is not a number)
- `pattern='[0-9]*'`, without which it doesn’t work on iOS

Based on the guidance here:
- https://github.com/alphagov/govuk-design-system-backlog/issues/74
- https://docs.google.com/document/d/1wozIhOdt6wvlgqVReauUnlsJI-3fqUlNuQFwUI7tqAA/edit
This commit is contained in:
Chris Hill-Scott
2018-05-07 22:26:24 +01:00
parent 4d678aec93
commit 063f9cc081
3 changed files with 15 additions and 3 deletions

View File

@@ -160,8 +160,15 @@ def password(label='Password'):
Blacklist(message='Choose a password thats harder to guess')])
class SMSCode(StringField):
def __call__(self, **kwargs):
return super().__call__(
type='tel', pattern='[0-9]*', **kwargs
)
def sms_code():
return StringField('Text message code', validators=[
return SMSCode('Text message code', validators=[
DataRequired(message='Cant be empty'),
Regexp(regex='^\d+$', message='Numbers only'),
Length(min=5, message='Not enough numbers'),