Skip to main content

onchange

Description​

Fires when changes are made and applied via the user interface

The 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 the fields property, if it is defined
  • type - (optional) filter type: "text" (default) | "number" | "date" | "tuple"
  • filter - (optional) the filter operator available for this type
  • predicate - (optional) Date part extractor ("month" or "year") for date fields
  • value - (optional) the value in the input field
  • includes - (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