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
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:
| Property | Description | Behaviour if not supplied |
|---|---|---|
validationHeader | Header of the Message | Header is "Server Validation Message" |
validationMessage | Text of the Message | No Notification is displayed |
messageType | Defines the MessageType to use | Uses 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: trueboolean- In this (very contrived) example the logic is that the
Ratingcolumn 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
> 20will return20- with amessageTypeof Warning and custom Message Header - value
< 10will return10- nomessageTypeset (so it defaults to Info) - value of exactly
15will be rejected - with amessageTypeof Error and custom Message Header
- value
- Any edits that don't break those rules - or which are not for the
Ratingcolumn - we ignore (and they will be processed normally).