feat: add optional-exposed extra field type to registration form
This defines optional extra fields that are not hidden under the toggle on the registration page.
This commit is contained in:
@@ -135,7 +135,7 @@ class FormDescription:
|
||||
|
||||
def add_field(
|
||||
self, name, label="", field_type="text", default="",
|
||||
placeholder="", instructions="", required=True, restrictions=None,
|
||||
placeholder="", instructions="", exposed=None, required=True, restrictions=None,
|
||||
options=None, include_default_option=False, error_messages=None,
|
||||
supplementalLink="", supplementalText=""
|
||||
):
|
||||
@@ -159,6 +159,9 @@ class FormDescription:
|
||||
instructions (unicode): Short instructions for using the field
|
||||
(e.g. "This is the email address you used when you registered.")
|
||||
|
||||
exposed (boolean): Whether the field is shown if not required.
|
||||
If the field is not set, the field will be visible if it's required.
|
||||
|
||||
required (boolean): Whether the field is required or optional.
|
||||
|
||||
restrictions (dict): Validation restrictions for the field.
|
||||
@@ -195,6 +198,9 @@ class FormDescription:
|
||||
)
|
||||
raise InvalidFieldError(msg)
|
||||
|
||||
if exposed is None:
|
||||
exposed = required
|
||||
|
||||
field_dict = {
|
||||
"name": name,
|
||||
"label": label,
|
||||
@@ -202,6 +208,7 @@ class FormDescription:
|
||||
"defaultValue": default,
|
||||
"placeholder": placeholder,
|
||||
"instructions": instructions,
|
||||
"exposed": exposed,
|
||||
"required": required,
|
||||
"restrictions": {},
|
||||
"errorMessages": {},
|
||||
@@ -268,6 +275,7 @@ class FormDescription:
|
||||
"label": "Cheese or Wine?",
|
||||
"defaultValue": "cheese",
|
||||
"type": "select",
|
||||
"exposed": True,
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"instructions": "",
|
||||
@@ -283,6 +291,7 @@ class FormDescription:
|
||||
"label": "comments",
|
||||
"defaultValue": "",
|
||||
"type": "text",
|
||||
"exposed": False,
|
||||
"required": False,
|
||||
"placeholder": "Any comments?",
|
||||
"instructions": "Please enter additional comments here."
|
||||
|
||||
@@ -95,6 +95,7 @@ class FormDescriptionTest(TestCase):
|
||||
placeholder="placeholder",
|
||||
instructions="instructions",
|
||||
required=True,
|
||||
exposed=True,
|
||||
restrictions={
|
||||
"min_length": 2,
|
||||
"max_length": 10
|
||||
@@ -110,8 +111,8 @@ class FormDescriptionTest(TestCase):
|
||||
json.dumps({'method': 'post',
|
||||
'submit_url': '/submit',
|
||||
'fields': [{'name': 'name', 'label': 'label', 'type': 'text', 'defaultValue': 'default',
|
||||
'placeholder': 'placeholder', 'instructions': 'instructions', 'required': True,
|
||||
'restrictions': {'min_length': 2, 'max_length': 10},
|
||||
'placeholder': 'placeholder', 'instructions': 'instructions', 'exposed': True,
|
||||
'required': True, 'restrictions': {'min_length': 2, 'max_length': 10},
|
||||
'errorMessages': {'required': 'You must provide a value!'},
|
||||
'supplementalLink': '', 'supplementalText': '',
|
||||
'loginIssueSupportLink': 'https://support.example.com/login-issue-help.html'}]})
|
||||
|
||||
Reference in New Issue
Block a user