save
type OnSaveResult = {
// qrray of keys of fields that were changed
changes: string[];
// map of current changed values (unsaved changes)
values: Record<string, any>;
};
onsave(ev: OnSaveResult): void;
event occurs when the user requests to save data in the editor. It is useful for processing changes and accessing the current values of fields.
If autoSave: true
, the event is triggered automatically on every field change.
If autoSave: false
, the event is triggered only when the Save button is clicked, and only if there are actual data changes.
note
If the editor has validation rules and validation fails for any field, the onsave
event will not be triggered.
Usage
Handling save request
<script>
import { Editor } from "wx-svelte-editor";
import { getData } from "../data";
const { items, values } = getData();
function onsave(ev) {
console.log("modified fields: ", ev.changes.join(", "));
console.log("latest data values", ev.values);
}
</script>
<Editor {items} {values} {onsave} />