Appearance
preInsert
The preInsert hook is executed before a row is inserted. It allows developers to prevent the insert based on custom logic.
Parameters
| Parameter | Type | Description |
|---|---|---|
| getColumnValue | function | See getColumnValue(columnName) |
| setColumnValue | function | See setColumnValue(columnName, columnValue) |
| setColumnStyle | function | See setColumnStyle(columnName, cssStyle) |
| setValidationError | function | See setValidationError(columnName, errorMessage) |
| unsetValidationError | function | See unsetValidationError(columnName) |
Return Value
Return false to cancel the insert, or true to proceed with the insert.
✨ Example of a preInsert Hook
This example prevents inserts when the column status has the value "DONE".
js
((getColumnValue, setColumnValue, setColumnStyle, setValidationError, unsetValidationError) => {
const value = getColumnValue("status")
if (value === "DONE") {
wpda.alert("ERROR", "Insert not allowed!") // Use built-in alert
wpda.snackbar("Insert not allowed!", "error") // Use built-in snackbar
return false
}
})