> For the complete documentation index, see [llms.txt](https://hichemtech.gitbook.io/reqease-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hichemtech.gitbook.io/reqease-docs/form-validation/validator-callbacks.md).

# Validator Callbacks

## Understanding Validator Callbacks

Validator Callbacks are functions in ReqEase that allow you to define custom behavior when the validation process encounters either a successful or failed outcome. These callbacks offer you the flexibility to respond to validation events according to your application's requirements.

### Available Callbacks

ReqEase's Form Validator supports two main methods in callbacks:

1. **onSuccess:** This callback is executed when the validation process succeeds, indicating that all validation rules and conditions have been met.
2. **onFailure:** Conversely, this callback is invoked when the validation process fails, indicating that at least one validation rule or condition was not met.

### Configuration Options

You can define your own custom callbacks by providing functions that take the Form Validator instance as a parameter. This allows you to perform specific actions when the validation process reaches either a successful or failed state.

Here's an example of defining custom callbacks:

```javascript
const customCallbacks = {
    onSuccess: (formValidator) => {
        // Custom logic to execute on validation success
        // Access the Form Validator instance if needed
    },
    onFailure: (formValidator) => {
        // Custom logic to execute on validation failure
        // Access the Form Validator instance if needed
    }
};


// add Form Validator opions to reqEase Options:
const reqEase = new ReqEase({
        // Other options...
    validation: {
        // Other options...
        callbacks: customCallbacks,
    }
});
```

## When to Use Validator Callbacks

Validator Callbacks are valuable when you need to react to the outcome of a validation process. Use them to trigger actions or display messages based on whether validation succeeded or failed. Typical use cases include showing error messages, disabling submission buttons, or triggering specific workflows depending on validation results.


---

# 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:

```
GET https://hichemtech.gitbook.io/reqease-docs/form-validation/validator-callbacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
