Commit 99c71706 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#4299 / HTML Element 'Select': Placeholder

AbstractBuildForm.php: code cleanup
parent 455f40db
......@@ -1457,7 +1457,6 @@ abstract class AbstractBuildForm {
* @param array $itemKey
* @param array $itemValue
*
* @return array
* @throws CodeException
* @throws \qfq\UserFormException
*/
......@@ -1510,24 +1509,17 @@ abstract class AbstractBuildForm {
$itemValue = OnArray::removeEmptyElementsFromArray($itemValue);
}
$placeholder = isset($formElement[FE_PLACEHOLDER]) ? $formElement[FE_PLACEHOLDER] : '';
// If a placeholder is configured but no emptyItemAtStart nor emptyItemAtEnd: force emptyItemAtStart
if ($placeholder != '' && !isset($formElement[FE_EMPTY_ITEM_AT_START]) && !isset($formElement[FE_EMPTY_ITEM_AT_END])) {
$formElement[FE_EMPTY_ITEM_AT_START] = '';
}
if (isset($formElement[FE_EMPTY_ITEM_AT_START])) {
$placeholder = isset($formElement[FE_PLACEHOLDER]) ? $formElement[FE_PLACEHOLDER] : '';
array_unshift($itemKey, '');
array_unshift($itemValue, $placeholder);
}
if (isset($formElement[FE_EMPTY_ITEM_AT_END])) {
$itemKey[] = '';
$itemValue[] = $placeholder;
$itemValue[] = '';
}
return $formElement;
}
/**
......@@ -2216,8 +2208,15 @@ abstract class AbstractBuildForm {
$itemValue = array();
$attribute = '';
if (!empty($formElement[FE_PLACEHOLDER])) {
$formElement[FE_EMPTY_ITEM_AT_START] = '';
if (isset($formElement[FE_EMPTY_ITEM_AT_END])) {
unset($formElement[FE_EMPTY_ITEM_AT_END]);
}
}
// Fill $itemKey & $itemValue
$formElement = $this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
......@@ -2242,13 +2241,9 @@ abstract class AbstractBuildForm {
$option .= Support::doAttribute('value', $itemKey[$ii], false);
if ($formElement[FE_PLACEHOLDER] != '') {
if (($ii == 0 && isset($formElement[FE_EMPTY_ITEM_AT_START])) ||
($ii == $total - 1 && isset($formElement[FE_EMPTY_ITEM_AT_END]))
) {
if ($ii == 0 && $formElement[FE_PLACEHOLDER] != '') {
$option .= 'disabled hidden ';
}
}
$jsonValues[] = [
'value' => $itemKey[$ii],
......
Supports Markdown
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