Skip to main content

Create new before-save hook (validation)

  1. If there is a need to validate values before saving - it is possible to use before-save hooks in the form
  2. For example, let's add a hook for timelog and check it has long description on how this time was spent
  3. In VS Code - open views/ui-code/index.ts and update the following:
beforeSave() {
entity.title ||= '(empty)';
if (entity.title.length < 50) {
throw 'Error: please provide longer task description - minimum 50 characters';
}
}
  1. Publish the app and try saving the timelog with the short explanation - the form will not save:
Before save validation