Add validations and transformations to your listeners
listener.use()
function and fire when the listener receives a corresponding
event.recordHook
has been configured to run on any Sheet matching
the slug “contacts”. The second parameter to the recordHook is a callback function where a Record, complete with it’s own get and set methods, is the incoming value.
npx flatfile@latest develop
again.
Now, in your Workbook, add a new Record. Enter a capitalized value in the First Name field, then click away so Flatfile knows you’ve finished your current edit.
Once your focus leaves the First Name field, an Event will trigger and the recordHook
will run the lowercase transformation you just configured.
recordHook
to help validate data.
For example, what if the first name in a Record is not a string? The current code would not transform it, so let’s add an error message to flag the Record.
recordHook
.
npx flatfile@latest develop
again.
Now, in your Workbook, add or update a Record. Enter a number inside the firstName field, or an invalid email address in the email field, then click away so Flatfile knows you’ve finished your current edit.
See that error message? That’s the result of your validation.