infinite-networks / InfiniteFormBundle

A collection of useful form types and extensions for Symfony.
169 stars 40 forks source link

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

Closed BorisDelprat closed 5 years ago

BorisDelprat commented 8 years ago

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.

King2500 commented 8 years ago

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

BorisDelprat commented 8 years ago
                   `                             /**
                         * @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

King2500 commented 8 years ago

Which Symfony version do you use?

merk commented 8 years ago

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.

blhylton commented 8 years ago

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 8 years ago

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

blhylton commented 8 years ago

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.

dameert commented 7 years ago

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.

dameert commented 7 years ago

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 7 years ago

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) }}"

jmclean commented 5 years ago

Tidying up old issues