Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attribute to fix B/C issue in list form field #44495

Open
wants to merge 9 commits into
base: 5.2-dev
Choose a base branch
from
17 changes: 10 additions & 7 deletions libraries/src/Form/Field/ListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ protected function getOptions()
$selected = ($selected === 'true' || $selected === 'selected' || $selected === '1');

$tmp = [
'value' => $value,
'text' => Text::alt($text, $fieldname),
'disable' => $disabled,
'class' => (string) $option['class'],
'selected' => ($checked || $selected),
'checked' => ($checked || $selected),
'value' => $value,
'text' => Text::alt($text, $fieldname),
'disable' => $disabled,
'class' => (string) $option['class'],
'selected' => ($checked || $selected),
'checked' => ($checked || $selected),
HLeithner marked this conversation as resolved.
Show resolved Hide resolved
];

// Set some event handler attributes. But really, should be using unobtrusive js.
Expand Down Expand Up @@ -191,7 +191,10 @@ protected function getOptions()
foreach ($options as $option) {
if ($option->value === $value) {
$value = $option->text;
$tmp->optionattr = ['data-global-value' => $option->value];

if (!$this->showonlocal) {
Ruud68 marked this conversation as resolved.
Show resolved Hide resolved
$tmp->optionattr = ['data-global-value' => $option->value];
}

break;
}
Expand Down
42 changes: 39 additions & 3 deletions libraries/src/Form/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ abstract class FormField implements DatabaseAwareInterface, CurrentUserInterface
*/
protected $showon;

/**
* Use the global (inherited) field value or local set field value on showon.
*
* @var boolean
* @since 3.2
Ruud68 marked this conversation as resolved.
Show resolved Hide resolved
*/
protected $showonlocal = false;
Ruud68 marked this conversation as resolved.
Show resolved Hide resolved

/**
* The parent class of the field
*
Expand Down Expand Up @@ -473,6 +481,7 @@ public function __get($name)
case 'spellcheck':
case 'validationtext':
case 'showon':
case 'showonlocal':
HLeithner marked this conversation as resolved.
Show resolved Hide resolved
case 'parentclass':
return $this->$name;

Expand Down Expand Up @@ -565,6 +574,7 @@ public function __set($name, $value)
case 'readonly':
case 'autofocus':
case 'hidden':
case 'showonlocal':
Ruud68 marked this conversation as resolved.
Show resolved Hide resolved
$value = (string) $value;
$this->$name = ($value === 'true' || $value === $name || $value === '1');
break;
Expand Down Expand Up @@ -656,9 +666,35 @@ public function setup(\SimpleXMLElement $element, $value, $group = null)
$this->group = $group;

$attributes = [
'multiple', 'name', 'id', 'hint', 'class', 'description', 'labelclass', 'onchange', 'onclick', 'validate', 'pattern', 'validationtext',
'default', 'required', 'disabled', 'readonly', 'autofocus', 'hidden', 'autocomplete', 'spellcheck', 'translateHint', 'translateLabel',
'translate_label', 'translateDescription', 'translate_description', 'size', 'showon', ];
'multiple',
'name',
'id',
'hint',
'class',
'description',
'labelclass',
'onchange',
'onclick',
'validate',
'pattern',
'validationtext',
'default',
'required',
'disabled',
'readonly',
'autofocus',
'hidden',
'autocomplete',
'spellcheck',
'translateHint',
'translateLabel',
'translate_label',
'translateDescription',
'translate_description',
'size',
'showon',
'showonlocal',
];
HLeithner marked this conversation as resolved.
Show resolved Hide resolved

$this->default = isset($element['value']) ? (string) $element['value'] : $this->default;

Expand Down