# 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/logic/index.ts** and update the following:

views/logic/index.ts

```
import { entity } from '#typings';
import type { ViewLogic } from '@comind/api';

export default {
    onBeforeSave,
} satisfies ViewLogic<typeof entity>;

function onBeforeSave() {
    entity.title ||= '(empty)';
    if (entity.title.length < 50) {
        return 'Please provide a longer task description - minimum 50 characters';
    }
}
```

4. Publish the app and try saving the timelog with the short explanation - the form will not save:

![Timelog form showing a validation error message when the description is too short](/assets/images/before-save-validation-d2b969dcd924183e13f251cf505082e6.png)

For a full reference on `onBeforeSave` and other lifecycle hooks (`onReady`, `onRefresh`, `onInputChange`), see [View logic - Lifecycle hooks](/developer-guide/building-blocks/view-logic.md#lifecycle-hooks).
