Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Current »

Validation rules are run when data is provided to the system, to check that the data conforms. This guide focuses on validating data which is inputted manually by users via fields.

Validation can be invoked by a number of actions. When the user:

  1. Dirties an individual field, i.e. on the fly, as they as entering content into a field. This is the primary validation method.

  2. Performs a “Save” action covering multiple fields. Fields which cannot be validated when they are dirtied should instead be validated on an action such as “Save” or “Confirm”. Actions which trigger a save can be made on the client-side or the back-end.

    1. Client-side: When fields are validated in bulk on the client-side, any invalid fields should apply the main guidelines defined below.

    2. Server side: A long term goal is for fields validated on the server side to also follow the main guidelines. As this is not feasible at the moment a separate set of guidelines exists for server side validation.

When a field contains invalid data it is in an “error state”. When in this state:

  • The data should not be saved

  • An error message should be displayed beneath the field

  • The user should be able to move freely around the form or page and not be locked to the field

  • Any save options should be inactive, unless validation for the field can only be run on “save”

  • If the user leaves the form or page they should see the standard “Unsaved changes” warning [link to be added]

Note that a field can be in a warning state, rather than an error state. Fields in a warning state can still be saved and are not considered to be invalid.

Feedback message

When a field contains invalid content, it should be made clear to the user what the problem is and how they can fix it.

Error messages should always include the name of the field to support accessibility guidelines.

Messages should be informative yet short. We should avoid using words such as “please”. [add more stop words?]

Empty mandatory field

When a mandatory field is empty the error message should state: “Enter a/an/the {field label}”.

image-20241211-140725.png

Invalid format

When a field contains invalid content the error message should always start with the field label and be informative but kept short. The error message should follow the format:

“{field label} must {description}”

Fields expecting an email address check for the format name@domain. The error message should read:

“{field label} must be a valid email address”

Fields expecting a URL check that http or https is included. The error message should read:

“{field label} must begin “http” or “https”

When a field’s content does not conform to any data restriction rules in place, the error message should follow the same format. For example, “Latitude must be a number between -90 and 90”

image-20241211-123509.png

Feedback presentation

Each validation message should be displayed underneath the relevant field. If the message takes up the full width of the field it should then wrap onto another row.

When a field in an error state:

  • The field background color should change to the standard error background color

  • Field label text and feedback text be displayed in the standard error foreground color [to be reviewed]

A field may instead be in a warning state. In this case the warning styles would be applied.

Dependent fields

Validation on save

When validation is run on a user triggered “save” action and errors are found, some guidelines, additional to those described above, must be applied:

  1. All invalid fields should be displayed in the error state

  2. Focus should move to the first invalid field

  3. An “error” toast should be displayed, letting the user know their submission contains errors and has not been saved. The toast should display:

    • A heading “Error”

    • The text “The {name/entity} was not saved. One or more fields are invalid. Please correct any errors and retry”

image-20241212-163550.png

Server side validation

When fields are validated on the server side, it is not possible to put an individual field into an “error” state in the UI. Instead any errors must be indicated in a toast message. The longer term goal is to bring server side validation inline with the above guidelines.

The toast should display:

  • A heading “Error”

  • The text “The {name/entity} was not saved. One or more fields are invalid. Please fix the following issue(s) and retry”

  • A list of errors in the form: {field label} must {description}

image-20241212-164110.png

The toast should display either until the user closes it, or when they re-trigger the validation.

  • No labels