[TYPO3-mvc] Fluid: how to render a multiple-select field as checkboxes?

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Apr 4 22:18:50 CEST 2011


Hey Francois,

> I'm currently working on an extension with FE input capabilities. One
> particular field is a select-type field (as defined in the TCA) with a
> list of options, whose rendering (in the FE) should be checkboxes.
...
> <f:form.checkbox property="liquidType" value="blood" checked="{0:
> incident.liquidType} == {0: 'blood'}"
> id="tx_latourrisk_liquidType_blood" />
> <f:form.checkbox property="liquidType" value="fluid" checked="{0:
> incident.liquidType} == {0: 'fluid'}"
> id="tx_latourrisk_liquidType_fluid" />
>
> With this setup it doesn't work if both checkboxes are checked, only the
> second value is taken into consideration when submitting the form. Is
> there a way to make it so that Fluid keeps both values?

I suppose your property "liquidType" is of type "string" and not of Type 
Array or similar (how should it if you have a CSV list). Because of 
this, Fluid is rendering only a singleValue checkbox. To still be able 
to use the CSV list in your model, you have to do some tricks.

a) adjust your model
Add a fake property of type Array and a according getter/setter pair to 
your domain model that's natively dealing with arrays, but is internally 
converting the data to the CSV and pass them to your liquidType 
property. Using this property then should actually let Fluid render the 
checkboxes correctly IIRC and checked/unchecked could also work. (don't 
forget to clear the caches after your modifications to renew the 
reflection cache)

b) manually convert the checkboxVHs to multivalue ones
If adjusting the model itself didn't do the trick on it's own, still use 
this property and manually switch the checkboxVH to a array style by 
simply not using the "property" attribute, but simply set the "name" 
attribute manually:
<f:form.checkbox name="objectNameInForm[liquidType][]" value="blood" .../>

> If yes, can the
> "checked" evaluation be made to work too (as it will obviously not work
> if the value is "blood,fuild")?

see above. Using the fake property should do the trick - but I'm not 
entirely sure - it's been a while since I used that VH in such a way.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list