# Validation

You can show your own warnings and errors on the widget's customer details step, on top of the
built‑in validation. You do it with the `onValidate` event.
You subscribe to the event in the widget code in the same way as you add a parameter,
with the `cbk(key, value)` method.

## onValidate event

The `onValidate` event is triggered every time a field in the customer form is changed.
Your function receives the current `values` of the form. It returns an object with `warnings`
and `errors`. Each is an array of strings. Either may be left out. Returning nothing means no
messages.

```javascript
cbk("onValidate", function(values) {
  // Return an object with arrays for warnings and errors
  return { warnings: [], errors: [] };
});
```

> **Note**
>
> Warnings will be shown to the user but do not block submitting the form.
> Errors will be shown to the user and will prevent submitting until resolved.

### Values

The `values` object contains the current state of the customer details form.
Custom fields are available on `values.custom`.

```json
{
  "name": "Full Name",
  "phone": "+46712345678",
  "email": "email@gmail.com",
  "custom": {
    "dogs-name": "Fido",
    "dogs-breed": "Beagle"
  }
}
```


### Example

This example shows a warning with a link when the custom field `dogs-breed` is `Beagle`.

```javascript
cbk("onValidate", function (values) {
  if (values.custom && values.custom['dogs-breed'] == 'Beagle') {
    return {
      warnings: ["Please fill this special Beagle form: [Link to Beagle form](https://cliento.com/)"]
    }
  }
});
```

> **Note**
>
> The content of `warnings` and `errors` supports Markdown for formatted content.
>
