Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etagwerker/6032632 to your computer and use it in GitHub Desktop.
Save etagwerker/6032632 to your computer and use it in GitHub Desktop.
Problem with backbone change callback, with different types for the same attribute.
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"
@etagwerker
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment