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
5 changes: 4 additions & 1 deletion libraries/src/Form/Field/ListField.php
Original file line number Diff line number Diff line change
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) {
$tmp->optionattr = ['data-global-value' => $option->value];
}

break;
}
Expand Down
12 changes: 11 additions & 1 deletion 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 __DEPLOY_VERSION__
*/
protected $showonLocal = false;

/**
* 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':
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':
$value = (string) $value;
$this->$name = ($value === 'true' || $value === $name || $value === '1');
break;
Expand Down Expand Up @@ -658,7 +668,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null)
$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', ];
'translate_label', 'translateDescription', 'translate_description', 'size', 'showon', 'showonLocal', ];

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

Expand Down