diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index e00cdf72710..66c48c98902 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -384,7 +384,14 @@ var SnippetEditor = Widget.extend({ val.data, this.options ); - this.styles[optionName || _.uniqueId('option')] = option; + var key = optionName || _.uniqueId('option'); + if (this.styles[key]) { + // If two snippet options use the same option name (and so use + // the same JS option), store the subsequent ones with a unique + // ID (TODO improve) + key = _.uniqueId(key); + } + this.styles[key] = option; option.__order = i++; var $optionSection = $(core.qweb.render('web_editor.customize_block_option')); $optionSection.append($el); @@ -581,27 +588,35 @@ var SnippetEditor = Widget.extend({ * @param {OdooEvent} ev */ _onOptionUpdate: function (ev) { + var self = this; + // If multiple option names are given, we suppose it should not be // propagated to parent editor if (ev.data.optionNames) { ev.stopPropagation(); - var self = this; _.each(ev.data.optionNames, function (name) { - var option = self.styles[name]; - if (option) { - option.notify(ev.data.name, ev.data.data); - } + notifyForEachMatchedOption(name); }); } // If one option name is given, we suppose it should be handle by the // first parent editor which can do it if (ev.data.optionName) { - var option = this.styles[ev.data.optionName]; - if (option) { + if (notifyForEachMatchedOption(ev.data.optionName)) { ev.stopPropagation(); - option.notify(ev.data.name, ev.data.data); } } + + function notifyForEachMatchedOption(name) { + var regex = new RegExp('^' + name + '\\d+$'); + var hasOption = false; + for (var key in self.styles) { + if (key === name || regex.test(key)) { + self.styles[key].notify(ev.data.name, ev.data.data); + hasOption = true; + } + } + return hasOption; + } }, /** * Called when the 'remove' button is clicked.