Validation Alerts

View as Markdown

Summary

  • Validation Alerts can prevent bad edits
  • They will fire before the edit is committed, preventing a round trip to the server

Validation Alerts can be used to prevent cell edits which break the rule set in the Alert Definition.

This is done by specifying PreventEdit in the AlertProperties property to true.

Note

If a Prevent Edit Alert is too inflexible, an Alert with an Undo action can be used instead

Validation Alerts are designed to avoid this common, and extremely annoying, scenario:

  1. an edit is made and commmitted
  2. all other users of the application see this edit
  3. server validation then kicks in and forces the cell to 'jump back' to its initial value in all users' grids

Hint

  • An alternative to validation Alerts is to 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
Alerts: Validation Alerts
Fork
  • This example contains a Validation Alert which prevents a cell edit which sets Github Stars to 0
  • It is of type Error and displays a Notification when the Alert fires
Try It Out
  • Set a GitHub Stars value to 0 and see the change being reverted and the Alert notification displayed
Loading demo…
Developer Guide

Providing Validation Alerts in Initial State

const initialState: InitialState = {
  Alert: {
    AlertDefinitions: [
      {
        Name: 'alert-no-zero-stars',
        MessageType: 'Error',
        MessageHeader: 'Invalid value',
        MessageText: 'GitHub Stars cannot be zero',
        Scope: {
          ColumnIds: ['github_stars'],
        },
        Rule: '[github_stars] = 0',
        AlertProperties: {
          PreventEdit: true,
          DisplayNotification: true,
        },
      },
      {
        Name: 'alert-no-negative-stars',
        MessageType: 'Error',
        Scope: {
          ColumnIds: ['github_stars'],
        },
        Rule: '[github_stars] < 0',
        AlertProperties: {
          PreventEdit: true,
          DisplayNotification: true,
          HighlightCell: true,
        },
      },
    ],
  },
};
1
Scope and Rule

Same shape as a Data Change Alert — Scope plus a boolean Rule evaluated on the proposed cell value.

2
Set PreventEdit

Set AlertProperties.PreventEdit to true to roll back the edit when the rule is true. Use DisplayNotification so users see why the edit was rejected.

FAQ

How do Validation Alerts differ from ReadOnly Cells The main difference is when the evaluation is performed:

  • Use ReadOnly cells ( via isEditable property in Edit Options) to validate before the edit (using the initial cell value)
  • Validation Alerts are evaluated after the proposed edit using the new cell value

AdapTable Resources