Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it usable from browser? #61

Open
mahiuddin opened this issue Aug 18, 2020 · 2 comments
Open

Is it usable from browser? #61

mahiuddin opened this issue Aug 18, 2020 · 2 comments

Comments

@mahiuddin
Copy link

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
Copy link
Member

Yes, but the bundle is not supplied - it is best to bundle together with your application code.

@smohadjer
Copy link

smohadjer commented Nov 27, 2023

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants