Skip to content

Commit

Permalink
Add class FieldsetForm
Browse files Browse the repository at this point in the history
  • Loading branch information
hnryjmes committed Jan 10, 2025
1 parent f20b5fd commit ff76484
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/assets/styles/overrides/_all.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "button";
@import "checkboxes";
@import "fieldset";
@import "file-upload";
@import "form-group";
@import "form-input";
Expand Down
11 changes: 11 additions & 0 deletions core/assets/styles/overrides/_fieldset.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fieldset {
.govuk-fieldset__legend--xl {
margin-bottom: 30px;
}

@media (min-width: 40.0625em) {
.govuk-fieldset__legend--xl {
margin-bottom: 50px;
}
}
}
26 changes: 26 additions & 0 deletions core/common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from crispy_forms_gds.choices import Choice
from crispy_forms_gds.layout import (
Div,
Fieldset,
HTML,
Layout,
Size,
Submit,
)
from django import forms
Expand Down Expand Up @@ -62,6 +64,30 @@ def get_layout_actions(self):
]


class FieldsetForm(BaseForm):
"""This is a suitable layout for a single question form. By using a
<fieldset> and <legend> it ensures that related inputs are grouped together
with a common label to enable users to easily identify the group, as
covered by WCAG Technique H71.
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.helper.layout = Layout(
Fieldset(
*self.get_layout_fields(),
legend=self.get_title(),
legend_size=Size.EXTRA_LARGE,
legend_tag="h1",
),
Div(
*self.get_layout_actions(),
css_class="govuk-button-group",
),
)


class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True

Expand Down
4 changes: 2 additions & 2 deletions exporter/core/organisation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from crispy_forms_gds.layout import HTML

from core.common.forms import BaseForm, TextChoice
from core.common.forms import BaseForm, FieldsetForm, TextChoice
from exporter.core.services import get_countries
from .validators import validate_phone
from exporter.core.organisation.services import validate_registration_number
Expand All @@ -27,7 +27,7 @@ def get_layout_fields(self):
return ()


class RegistrationTypeForm(BaseForm):
class RegistrationTypeForm(FieldsetForm):
class Layout:
TITLE = "Select the type of organisation"

Expand Down

0 comments on commit ff76484

Please sign in to comment.