Reputation: 483
In fluid code like this, how do I specify which items are preselected?
<f:form.select name="coupon" options="{couponoptions}" multiple="true" size="10"/>
the couponoptions is an array with uid values and name label pairs defined like so:
$coupons = $this->couponRepository->findAll();
foreach($coupons as $coupon) {
$couponoptions[$coupon->getUid()] = $coupon->getName();
}
The options all show up but I don't know how to specify which are preselected.
I am using typo3 v4.5.32 with fluid 1.3.
Thanks.
PS, the preselected items are found in php like so:
$old = $this->couponsAttachedRepository->findAll();
foreach($old as $o) {
$c = $o->getCoupon();
$couponsselected[$c->getUid()] = $c->getUid();
}
PPS: I would be happy to not use the f:form.select tag if I could get pass the options ina as a string like so {optionsstring} but when I try that the markup gets changed to html entities eg my < becomes '& lt;' etc. Is there way around that?
ANSWER from lorenz: ( I was so close, I just had to add the value like so)
<f:form.select name="coupon" options="{couponoptions}" value="{couponsselected}" multiple="true" size="10"/>
Upvotes: 0
Views: 2610
Reputation: 4558
You can use the value property to do a preselection, where the array key is the value:
PHP:
$couponOptions = array('a' => 'Value A', 'b' => 'Value B');
Fluid:
<f:form.select name="coupon" options="{couponOptions}" multiple="true" value="a" size="10"/>
Upvotes: 1