# Complex validations (custom)

Complex validations requiring algorithm implementation are implemented by developers and added to the validator library located in **Eximee Validation**. If validation is to be carried out through external services (e.g. an ESB bus), it is necessary to use **Service Proxy** in order to expose the given service.

If validations do not require connection to external services, lightweight script validators can be used (more in: [Script validators (validationScript)](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/walidatory-skryptowe-validationscript)). Complex validators can be used for application fields, pages, or complex components (used later in the application).

### Complex validations for components <a href="#walidacjezlozone-walidacjezlozonedlakomponentow" id="walidacjezlozone-walidacjezlozonedlakomponentow"></a>

In addition to mandatory fields and masks, specialized external validators can also be added to components.

#### **Attaching a validator**

To attach a validator, go into artifact edit mode and select any component that can have a validator attached. Then click the section **Data quality** in the component properties menu. After expanding the section, we will see the subsection **VALIDATORS**.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2F4MeP4CH1Q60LJ5wqoSRv%2Fimage.png?alt=media&#x26;token=060b9cc0-e3da-411d-b2c5-50b306e6e933" alt=""><figcaption><p><em>Figure 1. The "Data quality" section with the VALIDATORS subsection</em></p></figcaption></figure>

After clicking on **VALIDATORS** or the pencil icon, the validators window will slide out.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FAJf0ZQCKd5wMJbUMORhb%2Fimage.png?alt=media&#x26;token=05cc4bbd-f633-4f40-a257-f679486ca5ad" alt=""><figcaption><p align="center"><em><strong>Figure 2.</strong> Validators window</em></p></figcaption></figure>

After selecting the option **Select validator** we will be able to search for and select a given validator. The list contains standard validators and script validators. For a validator, a trigger condition can be defined (field **Add condition**). This is a JavaScript condition in which fields or session variables available in the application can be used. The method for creating conditions is described in [Expression language for defining conditions (conditions with getValue)](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/jezyk-wyrazen-definiowania-warunkow-warunki-z-getvalue).

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FMt2dU5eHcbatbpLg0gVO%2Fimage.png?alt=media&#x26;token=3eef22d1-7b90-410c-933b-51cd5f46a4e2" alt=""><figcaption><p align="center"><em><strong>Figure 3.</strong> Adding a validator</em></p></figcaption></figure>

#### **Simulation**

Validators, just like external services, support replacing their operation with a simulation script. Attaching such a script requires selecting the **Simulation** tab in the validators window and choosing the available simulation script from the list.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FjXNOLjYwgFvYvoHn21dS%2Fimage.png?alt=media&#x26;token=2f2421e6-bb34-46f8-8829-690d02e895b3" alt=""><figcaption><p align="center"><em><strong>Figure 4.</strong> Simulation script attachment tab</em></p></figcaption></figure>

From this level, we can also choose to create a new script by clicking the **Generate new script**button. The newly created script will automatically have content generated in accordance with the validator and the described separated code sections.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FPMolqKwvibDyEdSBXeVg%2Fimage.png?alt=media&#x26;token=c99d1913-5b6c-4ef6-8ae4-b2818c5c93f0" alt=""><figcaption><p align="center"><em><strong>Figure 5.</strong> Creating a simulation script</em></p></figcaption></figure>

Please note that such scripts will be run **only** when opening an application with **the** request logic simulation mode enabled!

### Complex validations on the page <a href="#walidacjezlozone-walidacjezlozonenastronie" id="walidacjezlozone-walidacjezlozonenastronie"></a>

#### **Adding validators on the page**

Validators can also be added on the page:

* If the page listens to the fields that we pass to the validator, the validator is called when the field the page is listening to changes.
* If the page does not listen to any fields, the validator will be called only after clicking the **Next/Submit.**\ <br>

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FSYWXG5hO5TQ76zuSKSVz%2Fimage.png?alt=media&#x26;token=d3fb8a8c-072e-4231-b4d1-1fc9140cd92b" alt=""><figcaption><p align="center"><em><strong>Figure 6.</strong> Properties panel with two validators added for the Page1 page</em></p></figcaption></figure>

#### **Adding** **validators on a complex component**

It is possible to add validators to a complex component. They will work as if they were added to the page on which the complex component is located.

### Adding translations for validation messages <a href="#walidacjezlozone-dodanietlumaczenkomunikatowwalidacji" id="walidacjezlozone-dodanietlumaczenkomunikatowwalidacji"></a>

Each validator returns a validation message. The content of the message may already be translated into Polish or may be in another language. After attaching the validator, go to the **Translations** tab and find the appropriate error key in order to change the translation.

If the validator message contains parameters, they should also be placed in the appropriate locations in the translation.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FLmk7usP2YfqKynsFaF3k%2Fimage.png?alt=media&#x26;token=922b77bc-3ec6-4818-9cc3-bfb1f2d70e31" alt=""><figcaption><p align="center"><em><strong>Figure 7.</strong> Example of message translations for a validator with parameter passing</em></p></figcaption></figure>

{% hint style="info" %}
More information in [Creating validators](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/walidatory-skryptowe-validationscript/tworzenie-i-podpiecie-walidatorow-skryptowych).
{% endhint %}
