Open
Description
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/[email protected]/+esm';
import ajvErrors from 'https://cdn.jsdelivr.net/npm/[email protected]/+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](https://private-user-images.githubusercontent.com/1375720/286302592-5bec0040-cfd9-48a1-9b15-56dd23ae3e69.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNDM1NzksIm5iZiI6MTczOTM0MzI3OSwicGF0aCI6Ii8xMzc1NzIwLzI4NjMwMjU5Mi01YmVjMDA0MC1jZmQ5LTQ4YTEtOWIxNS01NmRkMjNhZTNlNjkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTJUMDY1NDM5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzczODQ3OWEzNDFlOWM5MTc1NmE1YTFkNzNiZjAyM2ExMTg3MTdhM2NlZGM5Y2NhNWQ0MjNkOWYyN2ExNWI0NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.geQ7h2EBaDbwMQtoICQQXrrRynet9F0stiQeEkdtN8A)
Metadata
Assignees
Labels
No labels