mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
Add and use textarea component from GOV.UK Frontend
For the "Something else" branding form we want the form label to be the title. This brings in the textarea component from GOV.UK Frontend in order to do this since that contains code to set a the textarea label as the page heading in an accessible way. The rest of the textarea fields have not been switched to use the new component yet.
This commit is contained in:
@@ -812,6 +812,49 @@ class GovukCheckboxField(BooleanField):
|
||||
return govuk_checkbox_field_widget(self, field, param_extensions=param_extensions, **kwargs)
|
||||
|
||||
|
||||
class GovukTextareaField(TextAreaField):
|
||||
|
||||
def __init__(self, label='', validators=None, param_extensions=None, **kwargs):
|
||||
super(TextAreaField, self).__init__(label, validators, **kwargs)
|
||||
self.param_extensions = param_extensions
|
||||
|
||||
# self.__call__ renders the HTML for the field by:
|
||||
# 1. delegating to self.meta.render_field which
|
||||
# 2. calls field.widget
|
||||
# this bypasses that by making self.widget a method with the same interface as widget.__call__
|
||||
def widget(self, field, param_extensions=None, **kwargs):
|
||||
# error messages
|
||||
error_message = None
|
||||
if field.errors:
|
||||
error_message = {"text": field.errors[0]}
|
||||
|
||||
params = {
|
||||
"name": field.name,
|
||||
"id": field.id,
|
||||
"rows": 8,
|
||||
"label": {
|
||||
"text": field.label.text,
|
||||
"classes": None,
|
||||
"isPageHeading": False
|
||||
},
|
||||
"hint": {
|
||||
"text": None
|
||||
},
|
||||
"errorMessage": error_message
|
||||
}
|
||||
|
||||
# extend default params with any sent in during instantiation
|
||||
if self.param_extensions:
|
||||
merge_jsonlike(params, self.param_extensions)
|
||||
|
||||
# add any sent in though use in templates
|
||||
if param_extensions:
|
||||
merge_jsonlike(params, param_extensions)
|
||||
|
||||
return Markup(
|
||||
render_template('components/textarea/template.njk', params=params))
|
||||
|
||||
|
||||
# based on work done by @richardjpope: https://github.com/richardjpope/recourse/blob/master/recourse/forms.py#L6
|
||||
class GovukCheckboxesField(SelectMultipleField):
|
||||
|
||||
@@ -2210,7 +2253,19 @@ class BrandingOptions(StripWhitespaceForm):
|
||||
|
||||
|
||||
class SomethingElseBrandingForm(StripWhitespaceForm):
|
||||
something_else = TextAreaField('', validators=[DataRequired('Cannot be empty')])
|
||||
something_else = GovukTextareaField(
|
||||
'Describe the branding you want',
|
||||
validators=[DataRequired('Cannot be empty')],
|
||||
param_extensions={
|
||||
"label": {
|
||||
"isPageHeading": True,
|
||||
"classes": "govuk-label--l",
|
||||
},
|
||||
"hint": {
|
||||
"text": "Include links to your brand guidelines or examples of how to use your branding."
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ServiceDataRetentionForm(StripWhitespaceForm):
|
||||
|
||||
Reference in New Issue
Block a user