Skip to content

Commit

Permalink
Workaround Minicolors problem with updating swatches
Browse files Browse the repository at this point in the history
Minicolors can not handle when settings are updated with a shorter
array of swatches than initially passed (see
claviska/jquery-minicolors#287).

Minicolors converts the swatch strings to object and stores the
converted settings. When settings are updated, the new settings and
the old are deeply merged. If the new settings contain less swatch
colors, merging in the old settings adds a bunch of items to the
swatches array that have already been converted to objects. When
Minicolor proceeds to process the settings then, it cannot handle the
already converted items in the swatches array.

Minicolors stores its settings via `jQuery#data`. So before updating
the settings, we now remove the `swatches` property from the stored
settings. This way the settings object resulting from the deep merge
will only contan the new swatch color values.

REDMINE-17994
  • Loading branch information
tf committed Oct 9, 2020
1 parent 4b6d674 commit 6afec6b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package/src/ui/views/inputs/ColorInputView.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const ColorInputView = Marionette.ItemView.extend({
},

updateSettings: function() {
this.resetSwatchesInStoredSettings();

this.ui.input.minicolors('settings', {
defaultValue: this.defaultValue(),
swatches: this.getSwatches()
Expand All @@ -76,6 +78,16 @@ export const ColorInputView = Marionette.ItemView.extend({
this.load();
},

// see https://github.com/claviska/jquery-minicolors/issues/287
resetSwatchesInStoredSettings: function() {
const settings = this.ui.input.data('minicolors-settings');

if (settings) {
delete settings.swatches;
this.ui.input.data('minicolors-settings', settings);
}
},

load: function() {
this.ui.input.minicolors('value',
this.model.get(this.options.propertyName) || this.defaultValue());
Expand Down

0 comments on commit 6afec6b

Please sign in to comment.