Client Data Validation

View as Markdown

Summary

  • Client-side validation in AdapTable can be used to prevent invalid Edits from completing
  • They are essentially a special type of Alert

AdapTable provides Client Data Validation via Alerts (defined in Alert State)

Find Out More

AdapTable also offers Server Validation where the validation is handled externally

These Data Validation rules prevent cell edits before the new value is sent to the server.

Note

  • Ultimately, these are Alerts with PreventEdit set to true in the Alert definition.
  • If the Alert Rule is broken, AdapTable will undo the cell edit and fire the Alert.

This avoids the irritating scenario where an edit is made and committed which all other users of the application see before server validation forces the cell to 'jump back' to its initial value.

Caution

  • This is not the same as Pre-Edit Validation which prevents all edits to read-only cells
  • Client data validation is for the use case where a cell is editable but not all edits are necessarily valid
Client Data Validation
Fork
  • In this (slightly contrived) example, we have prevented cells in the language column being changed to Python (see adaptableOptions.ts).
  • The Alert displays a Toast Notification with a custom message and type Error at the top of the grid.
Try It Out
  • Change a cell in the language column to Python and see how it triggers a Prevent Edit Alert
  • Or go a stage further and create an Alert with a custom form enabling users to provide a new value. This can be achieved via an Adaptable Form with 2 Buttons that reference Grid API methods when clicked.
Loading demo…

Find Out More

FAQ

Why add Prevent Edit Alerts which perform validation on the client - surely it should take place on the server? That is correct, validation should ideally take place on the server and hopefully it does for our users. And AdapTable offers Server Validation for this reason. Instead Prevent Edit Alerts specifically deal with 3 common validation-related use cases:

  1. add an extra level of validation so that you can prevent edits which are usually permitted, but which in particular scenarios or use cases should be avoided

  2. avoid unnecessary round trips to the server, particularly if this has other knock-on consequences or affect other users that might see their screen flash first with the new value and then again with the old value

  3. as a temporary measure before Server Validation has been added; like all AdapTable objects, Alert Definitions will come into effect immediately after that they are created in the UI - there is no down-time needed, nor any custom development required, and no systems need to be restarted