Search.../

validate( )

Validates form fields and values against the registration form as defined in the site Dashboard.

Description

The validate() function returns a Promise that resolves to {valid: true} if the fields and values in the registration form are valid or rejects if there are invalid fields or values.

When the validate() function is called, the validateInput() function also runs for all your form fields.

The following are invalid when checked against the event's registration form as defined in the site Dashboard:

  • The specified form values contain a field that does not exist in the event's registration form.
  • The specified form values are missing a field that exists in the event's registration form. You must also include non-required fields even if their values are empty.

Note: To work with the Wix Events API, you need to publish your site.

Syntax

function validate(formValues: Array<FormValue>): Promise<ValidationResult>

validate Parameters

NAME
TYPE
DESCRIPTION
formValues
Array<FormValue>

Field names and values for a registration form.

Returns

Fulfilled - Validation result when validation passes. Rejected - FieldValidationError when validation fails.

Return Type:

Promise<ValidationResult>
NAME
TYPE
DESCRIPTION
valid
boolean

Indicates that the registration form field(s) are valid.

Was this helpful?

Validate a registration form

Copy Code
1import wixEventsFrontend from 'wix-events-frontend';
2
3// ...
4
5const eventId = // Get the event ID
6let form;
7
8wixEventsFrontend.getForm(eventId)
9 .then((result) => {
10 form = result;
11 });
12
13// ...
14
15let formValues = // get form values
16
17form.validate(formValues)
18 .then((response) => {
19 // handle case where form is valid
20 })
21 .catch((error) => {
22 // handle case where form is not valid
23 let message = error.message; // "Following fields have invalid IDs: nonExistent1, nonExistent2"
24 let fields = error.fields; // ["nonExistent1", "nonExistent2"]
25 });