Server Data Validation

Summary

  • Server-side validation can be used to validate (and undo) Edits via a function
  • An optional Message can be displayed to the User

AdapTable provides Server Validation, i.e. validation through a function provided by the user.

Find Out More

AdapTable also offers Client Validation where the validation is handled using Validation Alerts

This is available via the validateOnServer property in Edit Options.

If provided, the async function will be invoked by AdapTable each time a cell is edited.

Caution

This function will only be called after Client Validation has successfully completed

The function receives as an argument full details of the proposed edit and returns one of 3 values:

  • nothing - either the edit is valid, or it will be updated via the API or an alternate mechanism
  • the old value - i.e. validation failed so we should return the cell to it's previous value
  • a different value - often used if new value breaches upper or lower limits bounds (see example below)

validateOnServer

Runs Validation of Data Edits on the Server

Validation Message

Additionally, AdapTable can display a Notification to the user regarding the outcome of the Validation.

This is done via 3 optional properties provided in the ServerValidationResultobject returned by the function.

Note

This Notification Message is displayed in addition to allowing / cancelling the Edit

The 3 properties which can be returned are:

PropertyDescriptionBehaviour if not supplied
validationHeaderHeader of the MessageHeader is "Server Validation Message"
validationMessageText of the MessageNo Notification is displayed
messageTypeDefines the MessageType to useUses default of Info

Hint

The Notification behaviour (e.g. location, duration etc.) will be based on the settings in Notification Options

The Message only displays if displayServerValidationMessages in Edit Options is set to true (the default value).

displayServerValidationMessages

Default: true
boolean
Displays a Notification Message after Server Validation
Server Validation
Fork
  • In this (very contrived) example the logic is that the Rating column is editable but values must be between 10 and 20 (with 15 not allowed).
  • As a result 3 Server Validation Rules will be applied (and each will display a Message):
    • value > 20 will return 20 - with a messageType of Warning and custom Message Header
    • value < 10 will return 10 - no messageType set (so it defaults to Info)
    • value of exactly 15 will be rejected - with a messageType of Error and custom Message Header
  • Any edits that don't break those rules - or which are not for the Rating column - we ignore (and they will be processed normally).

Expand to see the Server Validation Rule

Server Validation

(Recorded with AdapTable v15.0)