habip_okcu
habip_okcu11mo ago

Frontend library addition and validation

Hi, I would like to add the "ajv" library as a frontend script for validation processes in Windmill. Is it possible? Additionally, I aim to apply validation to my frontend inputs one by one without using a submit form.
2 Replies
rubenf
rubenf11mo ago
You can use ajv in frontend if it supports esm and dynamic imports And load it from a cdn
habip_okcu
habip_okcu11mo ago
var ajvScript = document.createElement('script'); ajvScript.src = 'https://cdn.jsdelivr.net/npm/ajv/dist/ajv.bundle.js'; document.head.appendChild(ajvScript); ajvScript.onload = function () { const ajv = new window.Ajv(); const schema = { type: "object", properties: { foo: { type: "integer" }, bar: { type: "string" } }, required: ["foo"], additionalProperties: false }; const validate = ajv.compile(schema); const data = { foo: 42, bar: "example" }; const isValid = validate(data); if (isValid) { console.log("Data is valid!"); } else { console.error("Data validation error:", validate.errors); } }; I tried this type of usage, but I did not get successful results. Where am I making a mistake? The library I want to add supports ESM , but when I use the 'import' keyword in the Windmill frontend script, I get this error: 'Error running frontend script bg_1: Cannot use import statement outside a module.' Could you show me an example of adding a library using CDN?