Repository navigation
Open
Labels
enhancementNew feature or request
Milestone
Description
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
onSavehandler — 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;
}validateRowreturns 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).validateAllreturns 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
FieldErrorrendering 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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
[-]DataTable: per-row and cross-row validation[/-][+]Table: per-row and cross-row validation[/+]