Formidable icon indicating copy to clipboard operation
Formidable copied to clipboard

How to deal with ArrayCollections / ObjectSelect

Open chateaux opened this issue 6 years ago • 1 comments

I am using Formidable as an alternative to ZF3 forms and am liking it for its simplicity. However, I am wondering how to use it in more complicated forms?

For instance, if I have an Entity: Customer that has an option to select multiple Products, how do I go about doing this with Formidable?

In ZF3 I would create something like this:

$this->add( [ 'type' => 'DoctrineModule\Form\Element\ObjectSelect', 'name' => 'products', 'options' => [ 'object_manager' => $this->objectManager, 'target_class' => 'Domain\User\Products', ], 'attributes' => [ 'multiple' => true, ] ] );

When creating my form, it would have a multi-select option with all the products in it.

I am struggling to work out how to do this with Formidable?

Any suggestions would be appreciated!

chateaux avatar Mar 25 '18 20:03 chateaux

Sorry for the late reply, I was too distracted with life :)…

In Formidable, you'd create a RepeatedMapping which would wrap around a normal FieldMapping, to which you'd assign a formatter which resolves IDs (from the select) to actual entities and the other way around.

DASPRiD avatar Jun 19 '18 11:06 DASPRiD