ember-model icon indicating copy to clipboard operation
ember-model copied to clipboard

Fix dirty tracking for Number attr

Open dwickern opened this issue 10 years ago • 2 comments

Dirty tracking is broken when setting a number attr with a numeric string.

var Model = Ember.Model.extend({  num: attr(Number) });
var obj = Model.create({ num: 1 });
obj.set('num', '2'); // dirty
obj.save(); // clean
obj.set('num', '2'); // dirty !!

dwickern avatar Apr 15 '14 15:04 dwickern

This problem happens when I bind an input to a Number attribute. My workaround is to use a computed property in the controller which converts string to number in the setter:

myNum: function(key, value) {
    if (arguments.length > 1) {
        this.set('model.myNum', parseInt(value));
    }
    return this.get('model.myNum');
}.property('model.myNum')

dwickern avatar Apr 17 '14 16:04 dwickern

@jnovatnack can you take a stab at this? @dwickern has provided failing tests

ebryn avatar Apr 24 '14 04:04 ebryn