Skip to content

CodeCoupler UI DataSource Mixin "Validate"

Part of the CodeCoupler UI Pro package.

For now only the validation rule required will be used! All other rules will be supported in future releases.

The model allow you to define validation mechanisms in the field configuration property validation.

These validations are intended for data entry. So you can catch invalid inputs and do not even try to send them to the server. The origin datasource do not use these validations when syncing to the server. If you set an invalid value in a data item and you try to sync the datasource will send this invalid data to the server (where these will hopefully be rejected).

This mixin use the validation definitions when calling sync(). In case of an validation error the invalid values will not be send to the server. This has the advantage that not only user inputs are validated in a single step, but also data changes that are made programmatically.

In case of a validation error the following is carried out:

  • An change event followed by an error event a special error object will be triggered.
  • The promise of the sync method will be rejected with the same error object.

The error object that will be returned in the error event is:

1
2
3
{
  validationErrors: arrayOfFailedDataItems;
}

The arrayOfFailedDataItems include all data items of the datasource which do not pass. In each of these data items a property validationResults exists with the following structure:

1
2
3
4
5
{
  passed: false,
  required: [], //All fieldnames that is specified as "required"
  all: {} //All error messages of all fields with validation errors
}

Read more about the error message and how to modify them here: [https://docs.telerik.com/kendo-ui/controls/editors/validator/rules#custom-messages]

Normally the fieldname will be used in an error message. But you can define a special field configuration property visual.name. If defined this name will be used.

New Methods

The datasource extended with this mixin provides two new methods:

validate()

Validate all data items in the datasource. Returns an array with dataitems with validation errors. If no errors exists the array is emtpy.

validateDataItem(dataItem)

Validate a dataitem. A new property validationResults will be added to the dataitem. You can check with validationResults.pass if a validation error occured.