Search code examples
javascriptbackbone.js2-way-object-databinding

backbone stickit - reverting model changes


I'm now testing backbone stickit for two-way data binding. Is there a way to revert the changes, for example, while editing a model data through a form, the user press the cancel button, as in the pic below

enter image description here

It seems the model was changed on the fly as we type in the form. What I want is when the user press the cancel button, the model will revert to its original value.

I read about updateModel which need a true value to confirm the model update. However how can my edit-view [cancel-event] trigger a false value to the updateModel function, so that the model will not be updated with the textfield value.

Do I need something like a global variable?

//global variable
var updateModelTitle = true;

//backbone stickit bindings
  bindings: {
    '#title': {
      observe: 'title',
      updateModel: 'confirmUpdate'
    }
  },
  confirmUpdate: function(val, event, options) {
    return updateModelTitle;
  }

//cancel button event click event
updateModelTitle = false;

Thanks in advance for any help.


Solution

  • Try Backbone.Stickit's sister project: Backbone.trackit