1 | initial version |
You can exclude specific choices from a Symfony dropdown form type by setting the "choices" option to an array of key-value pairs, where the keys are the values of the options and the values are the labels. Then, use the "choices_exclude" option to specify which values to exclude from the dropdown.
Example:
$form = $this->createFormBuilder()
->add('my_options', ChoiceType::class, [
'choices' => [
'Option 1' => 'option1',
'Option 2' => 'option2',
'Option 3' => 'option3',
'Option 4' => 'option4',
],
'choices_exclude' => ['option2', 'option3'],
])
->getForm();
In this example, the dropdown will show four options ("Option 1", "Option 2", "Option 3", and "Option 4"), but exclude "Option 2" and "Option 3".