set event

Fires when the set method is invoked.

The set event is raised before the field value is updated. Calling the get method from the event handler will return the old value. Calling e.preventDefault will prevent the update of the field and the change event will not be triggered.

Event Data

e.field String

The name of the field which is retrieved.

e.value Number|String|Data|Object

The new value.

e.preventDefault Function

A function which may prevent the update of the value. Can be used to perform validation.

Example - subscribe to the set event

<script>
var observable = new kendo.data.ObservableObject({ name: "John Doe" });
observable.bind("set", function(e) {
/* The result can be observed in the DevTools(F12) console of the browser. */
    console.log(e.field); // will output the field name when the event is raised
});
observable.set("name", "Jane Doe"); // raises the "set" event and the handler outputs "name"
</script>

Example - perform validation by preventing the set event

<script>
var observable = new kendo.data.ObservableObject({ name: "John Doe" });
observable.bind("set", function(e) {
    if (e.field == "name") {
        if (!e.value) {
            // avoid emtpy value for the "name" field
            e.preventDefault();
        }
    }
});
observable.set("name", "Jane Doe");
</script>
In this article