Skip to main content

validation

interface OnValidationResult {
// map of field keys to actual values
values: Record<string, any>;
// map of fields keys to validation errors
errors: Record<string, string>;
}

onvalidation(ev: OnValidationResult): void

event is triggered when the validation process is completed. It provides the latest field values and any validation errors. This can be used to determine if the form is valid or to display error messages.

Usage

Handling validation results

<script>
import { Editor } from "wx-svelte-editor";

const items = [
{ comp: "text", key: "name", label: "Name",
validation: v => (v && v.length > 5) },
{
comp: "textarea",
key: "descr",
label: "Description"
},
{ comp: "checkbox", key: "admin", label: "Is Admin" }
];

function onvalidation(ev){
if (Object.keys(ev.errors).length > 0)
console.log("validation failed");
else
console.log("validation is ok");
console.log("latest data snapshot", ev.values);
}
</script>

<Editor {items} {onvalidation} />