-
Hi, how can I enable validation to work properly using custom editors? cellEditor: {
content: (props: ICellEditorProps) => {
const { rowData, column, value } = props;
props.autoFocus = true;
if (rowData && 'id' in rowData) {
const id: number = rowData['id'];
if (data.rows.length > id && data.rows[id].id === id && typeof rowData['id'] === 'number') {
const cell: TableCell | undefined = data.rows[id].cells.find(x => x.columnKey === column.key);
if (cell) {
switch (cell.data.dataType) {
case DataType.Boolean:
return (<CellEditorBoolean {...props} />)
case DataType.Date:
return (<CellEditorDate {...props} />)
case DataType.Object:
case DataType.String:
return (<CellEditorString {...props} />)
case DataType.Number:
const { min, max } = cell.data.limits;
if (!(min <= value && value <= max)) {
props.validationMessage = `not in [${min}; ${max}]`
return (
<div className={`${defaultOptions.css.kaCellEditorValidationError}`}>
<CellEditorNumber {...props} />
<CellEditorValidationMessage message={`not in [${min}; ${max}]`} />
</div>
);
}
return (<CellEditorNumber {...props} />)
default:
throw Error(`Non-exhaustive switch over DataType(dataType=${cell.data.dataType})`)
}
}
}
}
return;
}
} Adding a validation function to the "surrounding" table properties, doesn't work as well, because that function is never called for some reason, when using custom editors. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi @Yamahari try to override cellEditorInput instead of cellEditor childComponent option |
Beta Was this translation helpful? Give feedback.
-
Hi @komarovalexander , thanks for quick answer. Unfortunately, swapping "cellEditor" with "cellEditorInput" causes an infinite loop of calls to the "content" function, hanging up the website? |
Beta Was this translation helpful? Give feedback.
-
Could some functionality in the default editor "CellEditorBoolean/Date/String/Number" cause this? Should I maybe lift the functionality out of there, directly into 1 custom component? |
Beta Was this translation helpful? Give feedback.
-
I solved it by explicitly handling the CloseEditor action in the dispatch method, where I prevent the editor from closing when the value is not within specs |
Beta Was this translation helpful? Give feedback.
I solved it by explicitly handling the CloseEditor action in the dispatch method, where I prevent the editor from closing when the value is not within specs