> For the complete documentation index, see [llms.txt](https://docs.uibakery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uibakery.io/how-tos/custom-code/custom-validation.md).

# Implement custom validation

It might happen that you need to implement the advanced validation of the table or form fields based on a certain condition or data source request while editing or creating new records.

In the use case, we will set up validation of a date\&time field while editing a table record. If the validation fails, the edit action will not be executed and a user will see an error.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2Fgit-blob-dc1661d5fd61de13bfeac6e15dea660141028e75%2FCleanShot%202022-09-22%20at%2018.42.08.gif?alt=media" alt=""><figcaption></figcaption></figure>

1. Create a multi-step action. Add a **Condition** action as a first step. Specify the validation code, e.g.: `return new Date({{ui.table.editedRow.data.end_date}}) >= new Date({{ui.table.editedRow.data.start_date}});`

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2Fgit-blob-deedc2c3a0f9d9dd43283a29f08939b488657ae2%2FCleanShot%202022-09-22%20at%2018.33.52%402x.png?alt=media" alt=""><figcaption></figcaption></figure>

2\. For the <mark style="color:green;">**True**</mark> condition, add the edit action. For the <mark style="color:red;">**False**</mark> condition, add a **Code** action and specify the code with your custom error message, e.g.: `throw new Error("Start date can't be greater than end date.");`

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2Fgit-blob-d2579609b723049e6ddd4238755dbfcfbf87d707%2FCleanShot%202022-09-22%20at%2018.35.05%402x.png?alt=media" alt=""><figcaption></figcaption></figure>

3\. Next, proceed to the **Config** section of the action - **Toasts**. Tick the error message and refer to the action as `{{actions.yourAction.error.message}}`

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2Fgit-blob-9e9469945d22d850946dfd592141cb1284094533%2FCleanShot%202022-09-22%20at%2018.36.01%402x.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.uibakery.io/how-tos/custom-code/custom-validation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
