kendo-uitelerikkendo-observable

How trigger Kendo observable change event from javascript?


Title says it all.

I have this kendo observable example set up so that when the first name gets changed the last name will be changed to match it. However the example doesn't work if you change the name in javascript( see the code for Clicking on the registration button).

Thanks for any help.!!


Solution

  • inding to the models change event should fix things for you

    $(document).ready(function() {
        var viewModel = kendo.observable({
            firstName: "John",
            lastName: "Doe",
            genders: ["Male", "Female"],
            gender: "Male",
            agreed: false,
            confirmed: false,
            register: function(e) {
                this.set("firstName", "bobbyyyyy!!!");
                e.preventDefault();
    
                this.set("confirmed", true);
            },
            startOver: function() {
                this.set("confirmed", false);
                this.set("agreed", false);
                this.set("gender", "Male");
                this.set("firstName", "John");
                this.set("lastName", "Doe");
            },
    
          firstNameChangeEvent:function(e) {
    
            switch(e.field){
              case "firstName":
                this.set("lastName", this.get("firstName"));                 
                break;
            }
          }
        });
    
        viewModel.bind("change", viewModel.firstNameChangeEvent);
    
        kendo.bind($("#example"), viewModel);
    });