[Flow] Dynamically add element to array collection with fluid form
Carsten Bleicker
carsten at bleicker.de
Wed Aug 13 09:58:48 CEST 2014
The dynamic fields are not known to trusted properties wich is usualy build up by any formfield viewhelper.
I think in case of dynamic fields you need an initializeFooAction() wich allows these dynamic subsets.
something like this:
/**
* @return void
*/
protected function initializeCreateAction() {
$databaseServerMappingConfiguration = $this->arguments->getArgument('databaseServer')->getPropertyMappingConfiguration();
/** @var array $databaseServers */
$databaseServers = $this->request->getArgument('databaseServer');
foreach ($databaseServers as $key => $server) {
$databaseServerMappingConfiguration->forProperty('databaseUsers.' . $key)->allowAllProperties();
}
}
----------------------
Carsten Bleicker
Wülfingstraße 1
42477 Radevormwald
E-Mail: carsten at bleicker.de
Web: www.bleicker.de
Twitter: @carstenbleicker
Jabber: cbleicker at jabber.ccc.de
Telefon: +49 (0)171-2690845
Am 13.08.2014 um 09:41 schrieb Christian Loock <chl at vkf-renzel.de>:
> Hello,
>
> I am trying to build a form with fluid, that automatically adds entries to an ArrayCollection. The collection consists of entities, that shoukd be dynamically created and added to the collection. Inside the form, i add new fields via javascript.
>
> The generated fluid form looks somewhat like this:
>
>
>
> <input placeholder="databaseServer.databaseuser.username" class="form-control" type="text" name="databaseServer[databaseUsers][0][username]" value="xxx">
> <input placeholder="databaseServer.databaseuser.password" class="form-control" type="password" name="databaseServer[databaseUsers][0][password]" value="xxx">
> <input placeholder="databaseServer.databaseuser.username" class="form-control" type="text" name="databaseServer[databaseUsers][1][username]" value="xxx">
> <input placeholder="databaseServer.databaseuser.password" class="form-control" type="password" name="databaseServer[databaseUsers][1][password]" value="xxx">
>
>
> The first entry, is an existing entity. When I only try to submit the form with this one in it, it will safe with no problem.
> However, when i try to add a new row to the form, so that there is an entry that does not exist in the database, I get an exception:
>
>
> 1297759968: Exception while property mapping for target type
> "VKF\Deployment\Domain\Model\DatabaseServer", at property path
> "databaseUsers": It is not allowed to map property "1".
>
> You need to use $propertyMappingConfiguration->allowProperties('1') to enable mapping of this property.
>
>
> Does anybody know, why this happens?
>
>
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list