Skip to content
Snippets Groups Projects
Commit 4458f0a7 authored by Samuli Sillanpää's avatar Samuli Sillanpää Committed by Robert Lange
Browse files

Feedbackform: add support for select element placeholder. (#1432)

parent c4b4b2f7
Branches
Tags
No related merge requests found
...@@ -55,6 +55,14 @@ ...@@ -55,6 +55,14 @@
# label (string) Group label (translation key) # label (string) Group label (translation key)
# options (array) List of select values (translation keys) # options (array) List of select values (translation keys)
# #
# placeholder (string) Placeholder label (translation key). Used to instruct or force
# (when combined with 'required' attribute) the user to make a selection from the
# options-list. Only select elements with 'options' are supported.
# For text, textarea, email and url elements, a placeholder text can be configured
# by adding a HTML-attribute via 'settings', for example:
# settings:
# - [placeholder, Please select...]
#
#----------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------
forms: forms:
......
...@@ -220,7 +220,8 @@ class Form extends \Zend\Form\Form implements ...@@ -220,7 +220,8 @@ class Form extends \Zend\Form\Form implements
$element = []; $element = [];
$required = ['type', 'name']; $required = ['type', 'name'];
$optional = ['required', 'help','value', 'inputType', 'group']; $optional
= ['required', 'help','value', 'inputType', 'group', 'placeholder'];
foreach (array_merge($required, $optional) as $field foreach (array_merge($required, $optional) as $field
) { ) {
if (!isset($el[$field])) { if (!isset($el[$field])) {
...@@ -245,8 +246,29 @@ class Form extends \Zend\Form\Form implements ...@@ -245,8 +246,29 @@ class Form extends \Zend\Form\Form implements
} }
if (isset($el['options'])) { if (isset($el['options'])) {
$options = []; $options = [];
$isSelect = $elementType === 'select';
$placeholder = $element['placeholder'] ?? null;
if ($isSelect && $placeholder) {
// Add placeholder option (without value) for
// select element.
$options[] = [
'value' => '',
'label' => $this->translate($placeholder),
'attributes' => [
'selected' => 'selected', 'disabled' => 'disabled'
]
];
}
foreach ($el['options'] as $option) { foreach ($el['options'] as $option) {
$options[$option] = $this->translate($option); if ($isSelect) {
$options[] = [
'value' => $option,
'label' => $this->translate($option)
];
} else {
$options[$option] = $this->translate($option);
}
} }
$element['options'] = $options; $element['options'] = $options;
} elseif (isset($el['optionGroups'])) { } elseif (isset($el['optionGroups'])) {
......
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