Skip to content

Table: per-row and cross-row validation #164

Open

Description

@coloneljade

Problem

The DataTable MVP (#161) supports per-cell sync validators that run on blur. Some validation needs context the cell doesn't have:

  • Per-row validators — e.g. "end date must be after start date" (cross-field within a row)
  • Cross-row validators — e.g. "salary must be unique across the table", "at most one row may be marked default"
  • Save-time validators — checks that should run only when the user attempts to commit, not on every cell blur

The MVP cell validator gets (value, row), which can express row-level checks awkwardly (run on every cell blur, no awareness of save attempts) but cannot see other rows.

Impact

  • Consumers needing cross-field row validation duplicate logic per cell or run a manual pre-save check, leading to inconsistent error UX.
  • Cross-row constraints can't be expressed at all and have to be hoisted into the parent's onSave handler — but at that point, errors must be reflected back into the table somehow, with no built-in path.

Suggested Approach

Extend the validation lifecycle:

interface IDataTableColumn<T> {
  // existing per-cell validator (sync, runs on blur)
  validate?: (value: T[keyof T], row: T) => string | void;
}

interface IDataTableProps<T> {
  // new: row-level validator (sync, runs on row commit / save attempt)
  validateRow?: (row: T, index: number, allRows: T[]) => { [key in keyof T]?: string } | void;
  // new: table-level validator (sync, runs on save attempt)
  validateAll?: (rows: T[]) => Map<number, { [key in keyof T]?: string }> | void;
}
  • validateRow returns a partial map of column keys to error messages, scoped to a single row. Runs when the user attempts to commit a row (Enter outside edit mode, or Save).
  • validateAll returns a map from row index to per-cell error map. Runs when the user clicks Save. Used for cross-row constraints.
  • Errors from any layer surface via the existing FieldError rendering at the affected cell.
  • Save proceeds only when no validation layer reports errors; otherwise, focus jumps to the first error, error count announced via live region.

Context

Layered on top of #161 (DataTable MVP). Async validation (server round-trips) is a separate issue.

Activity

  1. added this to the DataTable milestone on May 4, 2026
  2. added
    enhancement
    on May 4, 2026
  3. changed the title [-]DataTable: per-row and cross-row validation[/-] [+]Table: per-row and cross-row validation[/+] on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions