onchange
Description
Fires when changes are made and applied via the user interfaceThe event is triggered when a user deletes a rule, updates a rule, toggles the logic (glue) button or clicks Apply to add a rule.
Usage
onchange: (
value: {
field: string | number,
type?: "number" | "text" | "date" | "tuple",
predicate?: "month" | "year",
filter?: string,
includes?: any[],
value?: any,
}
) => void;
Parameters
The callback of the event takes the value object with the following parameters:
field- (required) the id of a field. It should be one of the field id from thefieldsproperty, if it is definedtype- (optional) filter type: "text" (default) | "number" | "date" | "tuple"filter- (optional) the filter operator available for this typepredicate- (optional) Date part extractor ("month" or "year") for date fieldsvalue- (optional) the value in the input fieldincludes- (optional) an array of the included values (strings, numbers or dates).
Example
In the example below we track changes made to the filter and output the log:
<script>
import { getData } from "../data";
import { FilterEditor } from "@svar-ui/svelte-filter";
const { options } = getData();
function handleApply(ev) {
console.log(ev.value);
}
</script>
<FilterEditor
field="age"
{options}
onchange={handleChange}
/>
Related articles: FilterEditor Guide