ruhley / angular-color-picker

Vanilla AngularJS Color Picker Directive with no requirement on jQuery
http://ruhley.github.io/angular-color-picker/
MIT License
166 stars 79 forks source link

Unnecessary initial call to $setDirty() #91

Closed TheWizz closed 8 years ago

TheWizz commented 8 years ago

The color picker calls $setDirty() once immedately after being instantiated, even if there's no change to the model.This happens if there's already a value set on the model (not if the model value is undefined).

I was able to fix this by changing the watchNgModel function from this:

if (oldValue !== undefined && typeof this.$scope.control[0].$setDirty === 'function') {
    this.$scope.control[0].$setDirty();
}

to this

if (oldValue !== newValue && typeof this.$scope.control[0].$setDirty === 'function') {
    this.$scope.control[0].$setDirty();
}

I.e., comparing "oldValue !== newValue" rather than "oldValue !== undefined". This seems to be more in the spirit of when to call $setDirty() (i.e., when there's some real change to the data), and I haven't seen any problem after making this change. If you believe this is correct, I would appreciate if you could apply this simple change. Thanks.

-JM

ruhley commented 8 years ago

Hi @TheWizz,

The if surrounding this if used to have that check, but it got removed to fix another bug. I have now added that check for the $setDirty() if.

Fixed in commit 414598af694e46aed763889101879c95d74ef5a3 and released in v2.1.5

TheWizz commented 8 years ago

Thanks!

-JM

On 19 jul 2016, at 23:57, Ruhley notifications@github.com wrote:

Hi @TheWizz,

The if surrounding this if used to have that check, but it got removed to fix another bug. I have now added that check for the $setDirty() if.

Fixed in commit 414598a and released in v2.1.5

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.