Search code examples
phptypo3fluidtypo3-8.xtypo3-extensions

How do I make "<f:form.select>" a mandatory field (required)?


Users are required to pick an option from this select:

<f:form.select name="role" options="{role}" optionLabelField="title" optionValueField="uid" size="4" />

The fluid select element has no required or minItems-Attribute. I don't want to check for missing arguments in the controller because the form is quite complex and I don't want to make users enter all the data again after $this->redirect("show").

I would prefer to have exactly the same implementation as with :

<f:form.textfield name="foo" required="true" />

which works like a charm. How would I do this?


Solution

  • As Ghanshyam pointed out you have to add additionalAttributes="{required:'required'}" to the <f:form.select> element. It does not work with whitespace within the attribute value.