[TYPO3-mvc] form.select add empty option
Claus Due
claus at wildside.dk
Wed Mar 14 13:39:32 CET 2012
Hi Stefano,
The ->toArray() then array_unshift($options, $emptyOptionArray) is a fine solution, too :)
To explain the FED Select+Option ViewHelpers:
If you use <fed:form.select> and exclude the "options" argument, the FED ViewHelpers
will allow you to manually insert your <option> tags - and you can use <fed:form.option>
for those or simply render each <option> manually.
The main difference between the FED Select and Fluid's version is that "options" is not
a required attribute in the FED version - because you get additional <option> rendering
possibilities.
---
Cheers,
Claus
http://fedext.net
On Mar 14, 2012, at 1:06 PM, Stefano Cecere wrote:
> hi Claus
>
> i tried to understand, from http://fedext.net/fed-viewhelpers/form/select-option.html
> how to add an "empty" field before my objects arrays.. but could not :(
>
> so i ended up with the ->toArray() solution (and then merging the 0 =>'--' in the controller before giving the array to Fluid
>
> ciao
> stefano
>
>
> On Mon, 29 Aug 2011 19:28:09 +0200, Claus Due <claus at wildside.dk> wrote:
>
>> Hi Stefan,
>>
>> I have very recently submitted a patch for Fluid which will (if merged) allow you to exclude the "options" argument and manually add <optgroup> and <option> tags inside the <select> while still preserving the form's __hmac value. If you need it quickly you can find it in the extension "fed" [1] or you can wait for 1.4 / 4.6 which I hope will include the patch :)
>>
>> Alternatively you might prefer this:
>>
>> <f:form.select options="{f:if(condition: themes, then: themes, else: {mylabel: 'MyValue'})" />
>>
>> Which, of course, only uses the placeholder if your {themes} variable does not contain options or is not defined/passed in the template :)
>>
>> [1] http://fedext.net/viewhelpers/form/select/
>>
>> Cheers,
>> Claus Due
>>
>> PS: the SelectViewHelper does add an empty option for valid output when no options are given, but unfortunately you cannot specify what the option should contain (both value and label will be empty strings).
>>
>>
>> On Aug 29, 2011, at 6:50 PM, Stefan Frömken wrote:
>>
>>> Hello MVC-Team,
>>>
>>> I want to add a simple empty option to form.select. The result should look like this:
>>>
>>> <select ...>
>>> <option value="">--</option>
>>> ...
>>> </select>
>>>
>>> I tried it this way...but it don't works:
>>>
>>> <f:form.select options="{themes}" optionValueField="uid" optionLabelField="name" name="theme" value="--">
>>> <option value="">--</option>
>>> </f:form.select>
>>>
>>> Any other ideas?
>>>
>>> Stefan
>>> _______________________________________________
>>> TYPO3-project-typo3v4mvc mailing list
>>> TYPO3-project-typo3v4mvc at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>
>
>
> --
> ____ ___ __ _ ______________________
>
> Stefano Cecere
> KRUR studio
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
More information about the TYPO3-project-typo3v4mvc
mailing list