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

Not working in browser #155

Open
smohadjer opened this issue Nov 28, 2023 · 0 comments
Open

Not working in browser #155

smohadjer opened this issue Nov 28, 2023 · 0 comments

Comments

@smohadjer
Copy link

smohadjer commented Nov 28, 2023

I'm loading ajv and ajv-errors from cdn and importing them into my javascript (no framework), but for some reason I still get default error messages from ajv instead of custom error messages that I have added to my json schema. Below is my frontend code. Note that in my Node.js backend ajv-errors works perfectly, so I know that problem is not in my schema or code. Does ajv-errors support esm at all?

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

You can see the problem on below page if you enter a number for the name fields and submit the form:
https://form-liart-five.vercel.app/

Source code available at:
https://github.com/smohadjer/form

Screenshot 2023-11-28 at 16 11 17
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

1 participant