Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 557
jumper rbk Avatar asked Aug 28 '26 09:08

jumper rbk


1 Answers

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

like image 95
user2095627 Avatar answered Aug 29 '26 22:08

user2095627



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!