Skip to content Skip to sidebar Skip to footer

How To Enable/disable Save Button Of Backbone Form-view When User Changes Form Content

I have form which gets data from backbone model. When the form is shown, they have initially value set to backbone model. Now, if any field is edited, i want to enable 'save' butto

Solution 1:

A simple solution would be to make your view listen to your model's changes:

initialize: function () {
  if(this.model){
    this.model.fetch({
      success: function(model, resp) {
        this.model._attributes = resp; // create a copy of the original attributesthis.listenTo(this.model, 'change', function() {
          // when the model changes// maybe write some function to compare bothif(_.isEqual(this.model._attributes, this.model.toJSON())) {
            // disable
          }
          else {
            // able
          }
        });
      }
    });
  }

So, when the data comes back from the server, you create a copy, and then listen to your model's changes. If the new attributes equal the original, disable the button.

Post a Comment for "How To Enable/disable Save Button Of Backbone Form-view When User Changes Form Content"