Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mauriciolauffer/openui5-validator
A library to validate OpenUI5 fields
https://github.com/mauriciolauffer/openui5-validator
ajv javascript json-schema openui5 openui5-framework openui5-validator plugin sap sapui5 ui5 validation validator
Last synced: 3 months ago
JSON representation
A library to validate OpenUI5 fields
- Host: GitHub
- URL: https://github.com/mauriciolauffer/openui5-validator
- Owner: mauriciolauffer
- License: mit
- Created: 2017-08-14T10:24:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-05T23:56:49.000Z (about 1 year ago)
- Last Synced: 2024-10-09T04:27:40.735Z (3 months ago)
- Topics: ajv, javascript, json-schema, openui5, openui5-framework, openui5-validator, plugin, sap, sapui5, ui5, validation, validator
- Language: JavaScript
- Homepage: https://mauriciolauffer.github.io/openui5-validator/demo/webapp/index.html
- Size: 1.21 MB
- Stars: 18
- Watchers: 4
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# openui5-validator
[![npm](https://img.shields.io/npm/v/openui5-validator)](https://www.npmjs.com/package/openui5-validator) [![test](https://github.com/mauriciolauffer/openui5-validator/actions/workflows/test.yml/badge.svg)](https://github.com/mauriciolauffer/openui5-validator/actions/workflows/test.yml)
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
* [JSON schema specification](http://json-schema.org/)
* [Ajv documentation](https://github.com/epoberezkin/ajv)Ajv Options:
Ajv Keywords:
## Demo
You can check out a live demo here:
![Demo Screenshot](./openui5-validator.png)
## 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
```sh
$ 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:
```json
{
"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*:
```javascript
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
* LinkedIn: [https://www.linkedin.com/in/mauriciolauffer](https://www.linkedin.com/in/mauriciolauffer)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details