Commit 3ea1cd56 authored by NickWilde's avatar NickWilde

Issue #2999500 by NickWilde, ocastle: HTML5 Input Validation fails for some widgets

parent aac2761d
......@@ -24,6 +24,7 @@ color-field-widget-spectrum:
css:
component:
/libraries/spectrum/spectrum.css: {}
css/color_field_widget_spectrum.css: {}
license:
name: MIT
url: https://github.com/bgrins/spectrum/blob/master/LICENSE
......
......@@ -55,20 +55,3 @@ function color_field_theme() {
return $theme;
}
/**
* Prepares variables for the color_field formatter swatch template.
*
* This template outputs a color swatch.
*
* Default template: color-field-formatter-swatch.html.twig.
*
* @param array $variables
* An associative array containing:
* - color: The color background.
* - shape: The shape of the color swatch.
* - width: The width of the color swatch.
* - height: The height of the color swatch.
*/
function template_preprocess_color_field_formatter_swatch(array &$variables) {
}
......@@ -30,3 +30,12 @@
height: 32px;
width: 32px;
}
input.color_field_widget_box__color.required {
display: block !important;
width: 0;
height: 0;
padding: 0;
border: none;
overflow: hidden;
}
......@@ -2,3 +2,12 @@
z-index: 1;
max-width: 100%;
}
input.js-color-field-widget-grid__color.required {
display: block !important;
width: 0;
height: 0;
padding: 0;
border: none;
overflow: hidden;
}
input.js-color-field-widget-spectrum__color.required,
input.js-color-field-widget-spectrum__opacity.required {
display: block !important;
width: 0;
height: 0;
padding: 0;
border: none;
overflow: hidden;
}
......@@ -38,6 +38,7 @@ abstract class ColorFieldWidgetBase extends WidgetBase {
if ($this->getFieldSetting('opacity')) {
$element['color'] = $input;
$element['color']['#title'] = $this->t('Color');
$element['color']['#error_no_message'] = TRUE;
$element['#type'] = 'fieldset';
$element['opacity'] = [
......@@ -49,6 +50,7 @@ abstract class ColorFieldWidgetBase extends WidgetBase {
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->opacity) ? $items[$delta]->opacity : NULL,
'#placeholder' => $this->getSetting('placeholder_opacity'),
'#error_no_message' => TRUE,
];
}
else {
......
......@@ -108,7 +108,12 @@ class ColorFieldWidgetBox extends ColorFieldWidgetBase {
$element['color']['#default_value'] = '#' . $element['color']['#default_value'];
}
}
elseif ($element['#required']) {
// If the element is required but has no default value and the element is
// hidden like the color boxes widget does, prevent HTML5 Validation from
// being invisible and blocking save with no apparent reason.
$element['color']['#attributes']['class'][] = 'color_field_widget_box__color';
}
$element['#attached']['library'][] = 'color_field/color-field-widget-box';
// Set Drupal settings.
......
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