Skip to main content

Validation

The booking widget can be extended with custom validation in the customer details step. Use the onValidate event to add warnings and errors on top of the built‑in validation. The event can be subscribed in the widget code in the same way as adding parameters, using the cbk(key, value) method.

onValidate event

The onValidate event is triggered every time a field in the customer form is changed. The function receives the current form values and should return an object with the properties warnings and errors, both being arrays of strings.

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.

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

Example

Below is an example that demonstrates how to add warnings and errors based on the custom values.

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.