[TYPO3-mvc] Fluid: form.select view helper and empty default item

Nathan Lenz typo3 at k9tfk.com
Mon Feb 1 15:59:12 CET 2010


Susanne Moog wrote:
> Hey everyone,
> 
> I have a short question about the form.select view helper of fluid. How
> do you handle select boxes that should start with an empty item
> (optional attribute).
> 
> I want to render something like
> 
> <select name="category" size="1" id="category"><option value="">---</option>
> <option value="cat1">cat1</option>
> <option value="cat2">cat2</option>
> <option value="cat3">cat3</option>
> </select>
> 
> I'm using the following code atm (with the categories as object) and am
> unsure how to get an empty object at the beginning:
> 
> <f:form.select property="category" options="{categories}"
> optionLabelField="name" size="1" id="category" />
> 
> Thanks for any help,
> 
> Susanne

I've tried hacking in an empty object by both pushing an empty object
onto the front of the array and by just adding an empty string to the
front of the array from inside the controller.  This gives the intended
effect for creating new items or editing items that have never been
categorized.

However if you try editing an item and un-setting the category, the
mapper fails because it tries to run:  $categoryRepository->findByUid(0)
which throws an exception. I filed an issue at the forge about this not
too long ago.

Back to adding the empty option. Maybe there should be an option in the
view helper?

emptyOption="---"
emptyOption="Please select a category"

Something like that?

--Nathan





More information about the TYPO3-project-typo3v4mvc mailing list