8000 [Form] Collection / allow_delete / removes items unwillingly · Issue #14938 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Collection / allow_delete / removes items unwillingly #14938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dmaicher opened this issue Jun 10, 2015 · 8 comments
Closed

[Form] Collection / allow_delete / removes items unwillingly #14938

dmaicher opened this issue Jun 10, 2015 · 8 comments

Comments

@dmaicher
Copy link
Contributor

I think it might be a conceptual issue that I came across today. I created a minimal example to reproduce the issue:

https://github.com/dmaicher/symfony2-collection-problem

So basically its a simple form with a collection type:

class ConfigType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('options', 'collection', [
                'type' => new OptionType(),
                'allow_add' => true,
                'allow_delete' => true
            ])
            ->add('submit', 'submit')
        ;
    }

With this subform:

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('enabled', 'checkbox', [
                'required' => false
            ])
            ->add('name', 'text', [
                'disabled' => true
            ])
        ;
    }

As I set allow_delete to true one should be able to remove items client side. The problem is if I now uncheck the enabled checkbox for some of the options then the browser will not submit any values at all for those collection items (disabled field will be ignored & checkbox is not checked). So server side it seems like the whole form widget has been removed client side although that's not really the case here.

Anyone ever had this issue?

I guess the only solution for now is to add an additional unmapped field to the subform that will be submitted by the browser?

Like:

$form->add('_keep', 'hidden', [
    'mapped' => false,
    'data' => true
]);

Should this maybe be done automatically?

@dmaicher dmaicher changed the title Form / Collection / allow_delete / removes items unwillingly [Form] Collection / allow_delete / removes items unwillingly Jun 10, 2015
@xabbuh xabbuh added the Form label Jun 10, 2015
@shivas
Copy link
shivas commented Sep 17, 2015

Can confirm it is there... got same issue, and provided "fix" in this issue actually works. Looks like if only field in form is collection, and that collection is submitted as empty - symfony doesn't detect form submission at all.

In documentation of collection field, where there is cookbook with example of collection of emails, that example would not allow deleting last email in collection. Or deleting 8000 all emails at once.

@cybernet
Copy link
Contributor

this is still opened. I also have this problem 😞

@Simperfit
Copy link
Contributor

@cybernet Do you have some time to try to provide a fix ? If the bug is touching you it could ease the débugging process and the fix; tell me if you need help :).

@cybernet
Copy link
Contributor

@Simperfit should i open a new ticket ? - my problem is with CheckboxType & ChoiceType

@cybernet
Copy link
Contributor

lovely :)

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@dmaicher
Copy link
Contributor Author

There is a workaround. Closing for now.

@cybernet
Copy link
Contributor

There is a workaround. Closing for now.

thanks for sharing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0