openui5-validator
An OpenUI5 library that validates the fields of a view against a JSON schema using Ajv, returning a verdict and a list of failures and leaving reporting to the user to the app.
Field checks in a UI5 view tend to be written control by control. openui5/validator/Validator takes the whole view and a JSON schema instead: new Validator(view, schema), then validate() returns the verdict and getErrors() lists the failures. Its checks are AjvAjvA JSON Schema validator for JavaScript. Where something here validates against JSON Schema rather than against the CDS model, Ajv is what compiles the schema and runs it.'s, so every Ajv validation keyword can be used in the schema, and a third opt parameter passes initialisation options through to Ajv. The README documents no step that sets a value state or an error message on the controls; reporting back to the user is the application's. It is installed from npm and registered in the host app's manifest.
Facts
Where it sits
Who is behind it
In the atlas: maintains 16, contributes to 41, wrote 4@mauriciolauffermaintainer
What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
As a package
- Where it runs
- does not say
- Distributed through
- npm
Connections
Keeping a control and a model in step in both directions
Framework core: module loader, MVC runtime, binding, routing, theming
A JSON Schema validator for JavaScript. Where something here validates against JSON Schema rather than against the CDS model, Ajv is what compiles the schema and runs it.
Download
Install
npm add openui5-validatorDerived from the package name. No recipe recorded; the README has the configuration.
Where it sits in your app
Download
sap.ui.require.README
quoted from mauriciolauffer/openui5-validator under MIT, readopenui5-validator
An OpenUI5 library to validate fields.
This library uses Ajv, a JSON schema validator. All validation keywords available in Ajv can be used.
JSON Schema and Ajv
For any references, please follow
Ajv Options: https://github.com/epoberezkin/ajv#options
Ajv Keywords: https://github.com/epoberezkin/ajv#validation-keywords
Demo
You can check out a live demo here:
https://mauriciolauffer.github.io/openui5-validator/demo/webapp/index.html

Project Structure
- demo - Library's live demo
- dist - Distribution folder which contains the library ready to use
- src - Development folder
- test - Testing framework for the library
Getting started
Installation
Install openui5-validator as an npm module
$ npm install openui5-validator
Configure manifest.json
Add the library to sap.ui5/dependencies/libs and set its path in sap.ui5/resourceRoots in your manifest.json file, as follows:
{
"sap.ui5": {
"dependencies": {
"libs": {
"openui5.validator": {}
}
},
"resourceRoots": {
"openui5.validator": "./FOLDER_WHERE_YOU_PLACED_THE_LIBRARY/openui5/validator/"
}
}
}
How to use
Import openui5-validator to your UI5 controller using sap.ui.require:
sap.ui.require([
'openui5/validator/Validator'
], function (Validator) {
const validationSchema = {
properties: {
email: { //UI5 control ID
type: 'string',
format: 'email',
minLength: 3 //required
},
salary: { //UI5 control ID
type: 'number',
minimum: 0,
maximum: 9999999
},
birthdate: { //UI5 control ID
format: 'date'
}
}
};
const validator = new Validator(this.getView(), validationSchema);
if (validator.validate()) {
console.log('Valid!');
} else {
console.log('Invalid! Errors...');
console.dir(validator.getErrors());
}
});
Config Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| view | sap.ui.core.mvc.View | null | UI5 view which contains the fields to be validated. |
| schema | object | null | JSON schema used for validation |
| opt | object | null | Parameters to initialize Ajv |
Author
Mauricio Lauffer
License
This project is licensed under the MIT License - see the LICENSE file for details
History
Others providing
Compare all 5 on the Data binding page →- ui5-antaresui5-antaresA SAPUI5 library that generates OData V2 metadata-based dialogs, object pages and value helps with input validation, and wraps OData V2 requests in promises.independent, ui5SAPUI5 library generating OData V2 metadata-based dialogs and pagesfrom UI5
- openui5-model-json-crudopenui5-model-json-crudAn OpenUI5 library that extends JSONModel to send CRUD requests over HTTP with fetch, so its calls return Promises; the README documents the read method only.independent, ui5OpenUI5 JSONModel extension with CRUD over HTTPfrom UI5
- openui5-model-odata-v2-odatapromiseopenui5-model-odata-v2-odatapromiseAn OpenUI5 library that extends the OData V2 model, sap.ui.model.odata.v2.ODataModel, to support Promises; its README documents no usage, installation or API.independent, ui5OpenUI5 OData V2 model extension with Promisesfrom UI5
- @openui5/sap.ui.core@openui5/sap.ui.coreThe OpenUI5 core: the module loader, the MVC runtime, data binding, routing, theming and the test stack, which is everything a UI5 app does before a single community package is added.sap official, ui5Framework core: module loader, MVC runtime, binding, routing, themingfrom UI5
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
History in the atlas
- First seen.
For your agent
- Ref
artifact:mauriciolauffer-openui5-validator- JSON
- /artifacts/mauriciolauffer-openui5-validator.json
- MCP
- Connecting an agent