Useful helper class to work with validation errors.
Returns an instance of the ValidationErrors class.
Example:
Convert object with a description of errors into ValidationErrors instance.
Parameters:
Type | Name | Description |
---|---|---|
Object | jsonObject | An ValidationErrors description Object that will be turned into its instance. Expected structure: |
{field1: [“field1 error1”], field2: [“field2 error1”, “field2 error2”], …} |
Returns: new ValidationErrors
instance.
Example:
Create ValidationErrors instance with one error.
Parameters:
Type | Name | Description |
---|---|---|
string | field | Field name |
string | error | Error text |
Returns: new ValidationErrors
instance.
Example:
Unites several ValidationErrors instances into one.
Parameters:
Type | Name | Description |
---|---|---|
ValidationErrors | error1 | A ValidationErrors instance to be united with others passed in arguments |
ValidationErrors | error2 | (Optional) A ValidationErrors instance to be united with others passed in arguments |
ValidationErrors | errorN | (Optional) A ValidationErrors instance to be united with others passed in arguments |
Returns: new ValidationErrors
instance.
Add en error into the ValidationErrors instance.
Parameters:
Type | Name | Description |
---|---|---|
string | field | Field name |
string | errorText | Error text |
Returns: this
Example:
Clear errors list.
Returns: this
Clear errors of the specified field.
Parameters:
Type | Name | Description |
---|---|---|
string | field | Name of the field to be cleared from errors |
Returns: this
Example:
Return a new instance cloning this, so that the new instance will have the same structure, but a new memory address.
Returns: this
Get errors entries of this ValidationErrors instance.
Returns: Array with the following structure: [[“field1”, [“field1 error1”]], [“field2”, [“field2 error1”, “field2 error2”]], …]
Example:
Get field names array, that contain errors.
Returns: string[] or null(if there is no errors)
Example:
Get errors messages of the specified field.
Parameters:
Type | Name | Description |
---|---|---|
string | field | Field name to get errors of |
Returns: string[] or null(if there is no errors)
Example:
Check if the field has any errors.
Parameters:
Type | Name | Description |
---|---|---|
string | field | Field name to check validity of |
Returns: Boolean
Example:
Check if this ValidationErrors instance has any field with errors.
Returns: Boolean
Example:
Convert this ValidationErrors instance to plain JS Object.
Returns: Object with the following structure: {field1: [“field1 error1”], field2: [“field2 error1”, “field2 error2”], …}
Example: