Created
July 18, 2013 20:11
-
-
Save etagwerker/6032632 to your computer and use it in GitHub Desktop.
Problem with backbone change callback, with different types for the same attribute.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Order = Backbone.Model.extend({ | |
initialize: function() { | |
this.bind("change:shipping_method_id", this.persist); | |
}, | |
... | |
// If the Order is valid, it tries to persist it. | |
persist: function(model, name) { | |
if (this.vanillaValid("#checkout_form_confirm")) { | |
this.updateTotal(true); | |
} | |
}, | |
... | |
// Console | |
> model.changedAttributes()["shipping_method_id"] | |
19 | |
> model.previousAttributes()["shipping_method_id"] | |
"19" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem was in my Backbone.js view. It was grabbing a value from the DOM (a string) and setting it to the Model.
It should always set a number when possible.