save
interface OnSaveResult {
// array of keys of fields that were changed
changes: string[];
// map of field keys to actual values
values: Record<string, any>;
// map of field keys to validation errors
errors: Record<string, string>;
}
onsave(ev: OnSaveResult): void
event occurs when the user requests to save data in the editor. It is useful for processing changes, handling validation errors, and accessing the current values of fields.
Usage
Handling save request
<script>
import { Editor } from "wx-svelte-editor";
const items = [
{ comp: "text", key: "name", label: "Name" },
{
comp: "textarea",
key: "descr",
label: "Description"
},
{ comp: "checkbox", key: "admin", label: "Is Admin" }
];
function onsave(ev){
console.log("modified fields", ev.changes.join());
if (Object.keys(ev.errors).length > 0)
console.log("there are unresolved validation errors");
console.log("latest data snapshot", ev.values);
}
</script>
<Editor {items} {onsave} />
If the editor has validation rules and validation fails for any field, the onsave
event will not be triggered.