-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Form\Element\Select multiple is always required #6009
Conversation
@@ -270,4 +346,13 @@ protected function getOptionValue($key, $optionSpec) | |||
{ | |||
return is_array($optionSpec) ? $optionSpec['value'] : $key; | |||
} | |||
|
|||
/** | |||
* @return boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return bool
for consistency
@@ -235,6 +292,24 @@ public function getInputSpecification() | |||
'required' => true, | |||
); | |||
|
|||
if ($this->useHiddenElement() && $this->isMultiple()) { | |||
$unselectedValue = $this->getUnselectedValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if $unselectedValue
corresponds with a value in the dropdown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius It would either be marked as selected, or that value would be considered a default value.
If nothing is selected, the hidden value returns a string. If at least one value is selected, the select element sends an array. There is no conflict, because the results are different types. I have added a testcase to the dataPovider for your example. |
Form\Element\Select multiple is always required
Close #6009 Fixes #4750 Fixes #5842 Fixes doctrine/DoctrineModule#215
The Select Element is always required. The Validation fails (required) if the multiple select is unselected. It is not possible to send an empty list.
I added the option for an hidden element. If nothing is selected the empty hidden field is send (required).
Select Element has the new Option 'use_hidden_element' and 'unselected_value'.
The FormSelect Helper generates an hidden element before the select element.
Reference to other Issues.
#4750, #5842, doctrine/DoctrineModule#215