Required files
SCSS files required: _forms.controls.scss
, _forms.selects.scss
, _forms.radios.scss
, _forms.checkboxes.scss
, _forms.labels.scss
SCSS files optional: _objects.form-layout.scss
, _forms.validation.scss
Form layout
Note: some variables are in the settings file settings.forms.scss
and can be reassigned after the include of the file if required
Use the class .form
on the element that contains all the form elements
Form group
Use the class .form__group
to wrap each form field or group of fields. You could apply the class to a <fieldset>
as it has a similar meaning.
Form group includes a bottom margin of 30px (variable: $form-group-base-spacing
) to give space between fields
Note: global spacing helper classes can also be applied .m-b-none
, .m-b-xs
, .m-b-sm
, .m-b-md
etc.
Form field
Use the class .form__field
for each field (placement of class varies across elements).
The form field includes the max-width style (variable: $form-field-max-width
)
Note: Form fields can be used for the placement of error messages directly underneath, therefore it is best not to add a bottom margin
Form label
Use the class .form__label
for a form field label - which is styled as small, bold font.
The form label includes the max-width style (variable: $form-field-max-width
)
Disabled fields
All fields can use the disabled attribute which will apply the disabled styles, however the select element needs a class .is-disabled
added to the .select
Form validation
The following modifying classes can be applied the form group .form__group--error
and .form__group--valid
, which will apply validation styling to the field inside.
Error messages can be wrapped in the class .form__error
and placed directly following the form field
Inputs
Use the class .form__control
directly on a textual input
Note: the code example below uses other wrappers and classes from the above general guidelines which helps with layout and validation etc.
Text areas
Use the class .form__control
directly on a textarea
Note: the code example below uses other wrappers and classes from the above general guidelines which helps with layout and validation etc.
Selects
Select elements are styled via a wrapping <div>
which requires the class .select
Use the class .form__control
directly on a select
The chevron icon is a background image applied to the .select:after
element. See here for info on how to deal with background images in the UI Toolkit.
Note: the code example below uses other wrappers and classes from the above general guidelines which helps with layout and validation etc.
Fields required
Add the modifying class to the form label .form__label--required
Alternative form controls
To apply the alternative form control styling use the modifying class .form__control--alt
to any textual inputs, textareas or selects
Annoyingly the select wrapper .select
also needs a class .select--alt
to move the chevron flush to the right
Note: global helper classes are available to modify the styling and make a newsletter signup for example
Checkboxes
Checkbox elements are styled via a wrapping <label>
which requires the class .checkbox
.
Inside the label element should be the checkbox <input>
followed by a <span>
with the text required.
Radios
Radio elements are styled via a wrapping <label>
which requires the class .radio
.
Inside the label element should be the radio <input>
followed by a <span>
with the text required.
Radios that are functionally grouped together via the name attribute can have a wrapping div with the class .form__group
for styling as a group.
Radios can also be made inline by applying the modifying class .radio--inline
Fields inline
To display form fields inline, wrap all the form groups in a wrapper with a class .form__groups-inline
To include any other elements eg. button or text amongst the inline elements, they should also be wrapped with the class .form__group
Note that the fields are now inline-block and won't stretch to 100%, so you can add a min width helper class eg. .min-width-md
Fields in a grid
Fields can easily be put in a grid. When a .form__group
is used, the margin needs to be removed as the grid takes care of spacing.
The grid below has a .grid--gutter-sm
modifying class applied and a .m-b-none
helper class on each form__group
element.