Commit 796b06c9 authored by NickWilde's avatar NickWilde

Issue #2997004 by NickWilde: Grid widget settings aren't unique per widget on a page

parent 3e577316
......@@ -18,19 +18,18 @@
Drupal.behaviors.color_field_jquery_simple_color = {
attach: function (context, settings) {
var $context = $(context);
var settings = settings.color_field.color_field_widget_grid;
$context.find('.js-color-field-widget-grid__color').each(function (index, element) {
var $element = $(element);
var widgetSettings = settings.color_field.color_field_widget_grid[$(this).attr('id')];
$element.simpleColor({
cellWidth: settings.cell_width,
cellHeight: settings.cell_height,
cellMargin: settings.cell_margin,
boxWidth: settings.box_width,
boxHeight: settings.box_height
cellWidth: widgetSettings.cell_width,
cellHeight: widgetSettings.cell_height,
cellMargin: widgetSettings.cell_margin,
boxWidth: widgetSettings.box_width,
boxHeight: widgetSettings.box_height
});
});
}
......
......@@ -144,9 +144,10 @@ class ColorFieldWidgetGrid extends ColorFieldWidgetBase {
// Set Drupal settings.
$settings = $this->getSettings();
$element['#attached']['drupalSettings']['color_field']['color_field_widget_grid'] = $settings;
$element['#attached']['drupalSettings']['color_field']['color_field_widget_grid'][$element['#uid']] = $settings;
$element['color']['#attributes']['class'][] = 'js-color-field-widget-grid__color';
$element['color']['#attributes']['id'] = $element['#uid'];
$element['color']['#wrapper_attributes']['class'][] = 'clearfix';
return $element;
......
......@@ -199,4 +199,63 @@ class ColorFieldWidgetJavascriptTests extends JavascriptTestBase {
$this->assertEquals(1, count($alpha));
}
/**
* Test color_field_widget_grid widget.
*
* Unfortunately since the grid library ALSO uses clickable divs instead of
* buttons. We could use $session->evaluateScript() to do it but we'll
* presume it is tested internally and just test the basic integration.
*/
public function testColorFieldWidgetGrid() {
$this->form
->setComponent('field_color_repeat', [
'type' => 'color_field_widget_grid',
'settings' => [
'cell_width' => '20',
'cell_height' => '20',
'cell_margin' => '1',
'box_width' => '250',
'box_height' => '100',
'columns' => '16',
],
])
->setComponent('field_color', [
'type' => 'color_field_widget_grid',
'settings' => [
'cell_width' => '10',
'cell_height' => '10',
'cell_margin' => '1',
'box_width' => '115',
'box_height' => '20',
'columns' => '16',
],
])
->save();
$session = $this->getSession();
$web_assert = $this->assertSession();
$this->drupalGet('node/add/article');
$page = $session->getPage();
// Confirm that help text/label are present.
$web_assert->responseContains('Freeform Color');
$web_assert->responseContains('Color field description');
// Wait for elements to be generated.
$web_assert->waitForElementVisible('css', '.simpleColorDisplay');
// Confirm that two fields aren't sharing settings.
$boxes = $page->findAll('css', '.simpleColorDisplay');
$this->assertEquals(2, count($boxes));
$script = <<< HEREDOC
(function() {
fields = jQuery('.simpleColorDisplay');
return jQuery(fields[0]).width() == jQuery(fields[1]).width()
})()
HEREDOC;
$this->assertFalse($session->evaluateScript($script));
}
}
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