Commit 6545b8d6 authored by NickWilde's avatar NickWilde

Issue #2882634 by eric.chenchao, tamnv, DuneBL, rpayanm, NickWilde: Color...

Issue #2882634 by eric.chenchao, tamnv, DuneBL, rpayanm, NickWilde: Color spectrum widget palette values is duplicate when we add multiple paragraph
parent 6ba883e4
......@@ -20,12 +20,12 @@
var $context = $(context);
var spectrum_settings = settings.color_field.color_field_widget_spectrum;
$context.find('.js-color-field-widget-spectrum').each(function (index, element) {
var $element = $(element);
var $element_color = $element.find('.js-color-field-widget-spectrum__color');
var $element_opacity = $element.find('.js-color-field-widget-spectrum__opacity');
var spectrum_settings = settings.color_field.color_field_widget_spectrum[$element.attr('id')];
$element_color.spectrum({
showInitial: true,
......
......@@ -2,6 +2,7 @@
namespace Drupal\color_field\Plugin\Field\FieldWidget;
use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -110,6 +111,7 @@ class ColorFieldWidgetSpectrum extends WidgetBase {
$element['#theme_wrappers'] = ['color_field_widget_spectrum'];
$element['#attached']['library'][] = 'color_field/color-field-widget-spectrum';
$id = Html::getUniqueId('spectrum-' . $this->fieldDefinition->getName());
// Set Drupal settings.
$settings = $this->getSettings();
......@@ -139,7 +141,8 @@ class ColorFieldWidgetSpectrum extends WidgetBase {
}
$settings['show_alpha'] = $this->getFieldSetting('opacity');
$element['#attached']['drupalSettings']['color_field']['color_field_widget_spectrum'] = $settings;
$element['#attributes']['id'] = $id;
$element['#attached']['drupalSettings']['color_field']['color_field_widget_spectrum'][$id] = $settings;
// Prepare color.
$color = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment