10000 [Form] Keep selected choices when extra choices have been submitted · Issue #9738 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Keep selected choices when extra choices have been submitted #9738

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
trsteel88 opened this issue Dec 11, 2013 · 10 comments
Closed

[Form] Keep selected choices when extra choices have been submitted #9738

trsteel88 opened this issue Dec 11, 2013 · 10 comments

Comments

@trsteel88
Copy link
Contributor

I have an expanded form type. If I load the page, then someone deletes one of the entities that is in my available choices and I select/submit it I get an error. This behaviour is correct.

However, all the valid options I have chosen have no been unselected and the data reverts to the original value. Is there a way to stop this and use the values that were selected regardless of whether it is valid/invalid. Or potentially even just ignore invalid values?

@hacfi
Copy link
Contributor
hacfi commented Dec 12, 2013

@trsteel88 How does your controller look like? Are other form fields filled out? I’m a little busy at the moment but I can review the issue on Saturday.

@hacfi
Copy link
Contributor
hacfi commented Dec 15, 2013

@trsteel88 I’m trying to reproduce it with a fresh 2.3.7 (or which version are you on?) project. What do you refer to by "all the valid options I have chosen"? Do you mean options on the same entity field? So it is multiple true? Or other fields in the form? Other fields in the form are selected correctly in my case (see https://github.com/hacfi/symfony9738).

@hacfi
Copy link
Contributor
hacfi commented Dec 15, 2013

If you refer to the other selected options in the same field, here is what happens:
Symfony\Component\Form\Form::submit $dispatcher->dispatch(FormEvents::PRE_SUBMIT, $event) is dispatched on the entity form and the listener Symfony\Component\Form\Extension\Core\EventListener\FixCheckboxInputListener throws an TransformationFailedException exception which is caught at

} catch (TransformationFailedException $e) {
resetting the data.

Quick fix: Extend Symfony\Component\Form\Extension\Core\Type\ChoiceType and replace the FixCheckboxInputListener in line 73 with a new one which doesn’t throw the TransformationFailedException.

If this is a desired feature we can add an option to the field type.
/cc @bschussek

@hacfi
Copy link
Contributor
hacfi commented Jan 3, 2014

@trsteel88 ping

@trsteel88
Copy link
Contributor Author

Sorry, I missed the last few comments. I will provide an example on Monday (possibly earlier). Basically I have an expanded set of entities. If you select all of them and hit submit (after someone else deletes 1 of the entities in the set you have chosen because you loaded an older version) the entire set throws and error and none of the entities you chose are selected. I think it should reload with an error and all the entities you selected which are valid should be selected.

@hacfi
Copy link
Contributor
hacfi commented Jan 3, 2014

I can confirm that’s happening.

The reason is the following line: Symfony\Component\Form\Extension\Core\EventListener\FixCheckboxInputListener

See #9738 (comment) for my suggested solutions.

@trsteel88
Copy link
Contributor Author

Oh great. I will test it out ASAP.

@xabbuh
Copy link
Member
xabbuh commented Sep 23, 2018

Status: Reviewed

@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?

@xabbuh
Copy link
Member
xabbuh commented Dec 29, 2020

will be fixed by #39659

@carsonbot carsonbot removed the Stalled label Dec 29, 2020
xabbuh added a commit that referenced this issue Feb 15, 2021
…s are submitted (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] keep valid submitted choices when additional choices are submitted

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #9738
| License       | MIT
| Doc PR        |

Commits
-------

85989c3 keep valid submitted choices when additional choices are submitted
@xabbuh xabbuh closed this as completed Feb 15, 2021
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

5 participants
0