0

I have registered a method on a 'change' event for a dropdown list as follows:

this.$el_period.on('change', function () {that.my_method();});

In my_method, I can get the new value that was selected but I would like to know if it is possible to get the previous value from which the user switched.

Thank's

Tomasz Jakub Rup
  • 9,464
  • 7
  • 44
  • 47
MarAja
  • 1,325
  • 2
  • 19
  • 31
  • Possible duplicate of [Getting value of select (dropdown) before change](http://stackoverflow.com/questions/4076770/getting-value-of-select-dropdown-before-change) – Tomasz Jakub Rup Aug 22 '16 at 11:04
  • @TomaszJakubRup, the problem is similar but I am using Backbone.js framework in my project and it is not the case in your linked question. The related question is about doing it with javascript/jquery, mine is about javascript/backbone. – MarAja Aug 23 '16 at 08:56
  • If You set event directly on DOM element, does not matter You use Backbone.js, jQuery or other Framework/library. Try solution from this answer. – Tomasz Jakub Rup Aug 23 '16 at 10:12

1 Answers1

0

Yes. That is possible to get previous state.

From the documentation:

var bill = new Backbone.Model({
name: "Bill Smith"
});

bill.on("change:name", function(model, name) {
    alert("Changed name from " + bill.previous("name") + " to " + name);
});

bill.set({name : "Bill Jones"});

Docs: https://backbonejs.org/#Model-previous