Is it usable from browser?
mahiuddin opened this issue · 2 comments
mahiuddin commented
I am using ajv validation from browser. By adding the following code in the HTML page.
<script src="js/ajv.min.js"></script>Is there any way or possible to use ajv-errors in the HTML page. I had tried to use by the following default in the html page. But it is not working.
var ajv = new Ajv({allErrors: true}); // options can be passed, e.g. {allErrors: true}
var schemaForRegCheck ={
"type": "number",
"minimum": 10,
"additionalProperties": false,
"errorMessage": 'this is a custom error messages'
}
Thank you advance.
epoberezkin commented
Yes, but the bundle is not supplied - it is best to bundle together with your application code.
smohadjer commented
Did you get it working in browser? I'm using it in following way, but I don't get any custom error messages!
import Ajv from 'https://cdn.jsdelivr.net/npm/ajv@8.12.0/+esm';
import ajvErrors from 'https://cdn.jsdelivr.net/npm/ajv-errors@3.0.0/+esm';
const ajv = new Ajv({
allErrors: true,
strict: false
});
ajvErrors(ajv);
const validator = ajv.compile(mySchema);
const valid = validator(json);
if (!valid) {
console.log(validator.errors);
}