Server-side validation of submitted Form values.
Checks the values a client posts against the Form definition, using the same rules the Form component applies in the browser,
so a request that bypasses the client validation is still rejected.
Methods
(static) validate(definitionJson, valuesJson, isActiveopt) → {Object}
Validates the submitted form values against the form definition.
Every active field is checked on its required flag and validation settings (data type, length, range, pattern and compare).
Failed rules are returned as Validator rule types (componyx.UI.Validator.TypeOption) per value path, so the client can show its own localized message for each rule.
Parameters:
| Name |
Type |
Attributes |
Description |
definitionJson |
string
|
|
The form definition JSON. |
valuesJson |
string
|
|
The submitted form values JSON. Fields are stored by name or binding key. A repeatable field set is stored as an object key, where the key is the field set id and the value is the array of repeated values. |
isActive |
function
|
<optional>
|
Determines whether a field is validated (default: visible and not disabled). |
Returns:
The validation result with the failed rule types per value path.
-
Type
-
Object
Example
import { validate } from './FormValidator.js';
const result = validate(definitionJson, valuesJson);
if (!result.isValid)
{
// result.errors looks like: { "email": [1], "addresses[0].zipCode": [0] }
}