DASPRiD / Formidable

PHP 7 form library for handling user input
BSD 2-Clause "Simplified" License
27 stars 7 forks source link

How to deal with ArrayCollections / ObjectSelect #19

Open chateaux opened 6 years ago

chateaux commented 6 years ago

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!

DASPRiD commented 6 years ago

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.