change
interface OnChangeResult {
// key of changed field
key: string;
// new value
value: any;
// map of all not saved changes, maps keys to values
update: Record<string, any>;
}
onchange(ev: OnChangeResult): void
event is triggered when a change occurs in any field of the editor. It is useful for tracking user input and managing unsaved changes.
Usage
Detecting changes in editor fields
<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 onchange(ev){
console.log(`field ${ev.key} was changed to ${ev.value}`);
console.log("all not saved changes", ev.update);
}
</script>
<Editor {items} {onchange} />