infinite-networks/InfiniteFormBundle

"Unable to determine the Type for given data" error in API since 1.0.4

BorisDelprat opened this issue · 11 comments

Hi guys!
I just wanted to share an issue that i found.
InfiniteFormBundle works really well in App and API until version 1.0.4, where it works in App but no more in API (with Fos_RESTBundle).
The error is "Unable to determine the Type for given data", in the file ResizePolyFormListener.
The condition !array_key_exists($data[$this->typeFieldName], $this->typeMap) in "getTypeForData" method return a false.
$data[$this->typeFieldName] equals the alias of the class in a string, $this->typeMap equals the fullName in an object.
I don't have time to go further but this issue need to be fixed for next versions of the bundle to works in API.
I had to take v 1.0.3 to work in API without any error
Thanks guys.

Can you show us how you configured your formtype? Especially the PolyCollection options.

                   `                             /**
                         * @param FormBuilderInterface $builder
                         * @param array $options
                         */
                        public function buildForm(FormBuilderInterface $builder, array $options)
                        {
                            $builder
                                ->add('moyen_coms', 'infinite_form_polycollection', array(
                                    'property_path' => 'moyenComs',
                                    'types' => array(
                                        'nucleus_moyencombundle_email', // The first defined Type becomes the default
                                        'nucleus_moyencombundle_telfixe',
                                        'nucleus_moyencombundle_telmobile',
                                        'nucleus_moyencombundle_teltelecopie',
                                        'nucleus_moyencombundle_adresse',
                                    ),
                                    'allow_add' => true,
                                    'allow_delete' => true,
                                    'by_reference' => false,
                                ));
                                                   }`

I'm sorry i really don't have much time for this but my form works in APP but not in API after version 1.0.3.
If i stay in 1.0.3 it works in both cases.
Thanks

Which Symfony version do you use?

merk commented

Thanks for the report:

Nothing that changed between 1.0.3 and 1.0.5 that I'm aware of that should be causing this problem. We're going to need more information. Please provide:

The output from composer show, the controller code that creates and submits the form type you pasted above and examples of the working and failing requests.

We need this information to trace what is happening, and when we have that we can write test cases to make sure these failures do not reoccur.

Seeing this same behavior, and rolling back to 1.0.3 from 1.0.6 corrected the issue. I'm on a tight deadline with the project using this, but in the coming weeks I can likely find time to provide you with any information you need to track this down.

merk commented

Thanks, any extra information, even a failing test case would help immensely to find the issue.

Sure thing, I actually have the project on BitBucket as a private repo if I can share it with you there. If that doesn't work, I can isolate the files that utilize the bundle and upload them as their own project here.

At the moment I am encountering the same error. In my case it depends on how I implement my twig file. Everything works fine when I render the prototype (add) button with form_row:

<a href="#" data-prototype="{{ form_row(prototype) | escape }}" class="btn btn-app add_item">Add</a>

However, this renders a label (index), my field label, and my field. Which is not so pretty. Thus I decided to use form_widget in stead of form_row to prevent the index label from printing. As soon as I do this:

<a href="#" data-prototype="{{ form_widget(prototype) | escape }}" class="btn btn-app add_item">Add</a>

the prototype keeps functioning, however on creation (submit) of the form I get the error described by @BorisDelprat .

Now I found where this is occurring I will try to dig deeper in the issue. As soon as I find something of interest I will report back.

Oops, after all it is not related to the use of form_row or form_widget. I simply forgot to render the _type field of my form! :-(
{{ form_row(form._type) }} This solved the error for me.

merk commented

Maybe we should add to the error that is being returned to make sure the _type hidden widget is rendered. "Make sure you have rendered the _type field for each poly collection: {{ form_widget(field._type) }}"

Tidying up old issues