When designing forms, you should not forget to apply inline validation to them. This will ensure that whoever is asked to fill it in, will be instantly prompted to correct a mistake, should it occur, before submitting the form.
This will ensure that the experience is smooth and the probablility of the data loss is reduced to a minimum.
Notice
Inline validation should not be used on its own. Please, make sure there is always server-side validation in place, to minimise the risk of processing invalid data.
Requirements
By default, WFP recommends a jQuery Validation Plugin, which is well documented and actively supported. Please, refer to its documentation for ways to implement inline validation for your forms.
To properly mark up your forms, follow the examples below. Make sure to load forms.css
stylesheet to have all required styles applied to your forms automatically.
NOTE
You are free to use your own validator script as long as the validation can be done according to the general guidelines and uses the UI styles showcased below.
Generally all types of fields can follow the same patterns. If you have a very specific case where it would be difficult to apply them, you can use a custom one, as long at it follows general visual guidelines set in the examples below (colours and display).
Form validation requires generally the following:
- to add attribute required
to elements which are mandatory;
- to add a correct value for the type
attribute (such as email
or number
;
- (optional) to add a pattern
attribute, which will provide a base for native HTML5 validation (only for supported browsers or compatible validation plugins).
For more information about available HTML5 input
attributes, visit Mozilla Developer Network pages.
“Invalid” Pattern
To correctly show an invalid field, add class invalid
to an input element. Next, insert error description using span
with a class error
just below the input.
Example
Sample Markup
“Valid” Pattern
When inputs are validated successfuly, you should replace their invalid
class with valid
and remove or hide the error description.