Skip to content

Commit

Permalink
Add HTML validation to registration form
Browse files Browse the repository at this point in the history
  • Loading branch information
rebecca-shoptaw committed May 8, 2024
1 parent 162a280 commit 385aa82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion openlibrary/plugins/upstream/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from openlibrary.utils.form import (
Form,
Textbox,
Email,
Password,
Checkbox,
Hidden,
Expand Down Expand Up @@ -73,11 +74,12 @@ def valid(self, value):

class RegisterForm(Form):
INPUTS = [
Textbox(
Email(
'email',
description=_('Your email address'),
klass='required',
id='emailAddr',
required="true",
validators=[
vemail,
email_not_already_used,
Expand All @@ -95,12 +97,18 @@ class RegisterForm(Form):
help=_("Letters and numbers only please, and at least 3 characters."),
autocapitalize="off",
validators=[vlogin, username_validator],
pattern="[a-zA-Z0-9]{3,20}",
title=_("Between 3 and 20 letters and numbers"),
required="true",
),
Password(
'password',
description=_('Choose a password'),
klass='required',
validators=[vpass],
minlength="3",
maxlength="20",
required="true",
),
Checkbox(
'ia_newsletter',
Expand Down
11 changes: 11 additions & 0 deletions openlibrary/utils/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ def get_type(self):
return "password"


class Email(Input):
"""Email input.
>>> Email("email", value='[email protected]').render()
'<input type="email" id="email" value="[email protected]" name="email" />'
"""

def get_type(self):
return "email"


class Checkbox(Input):
"""Checkbox input."""

Expand Down

0 comments on commit 385aa82

Please sign in to comment.