-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form][2.7] Incorrect/invalid select tag is generated if choices have duplicate content #15606
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
Comments
For the record this is also happening when using expanded choice list |
Might have something to do with the Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList::flatten() method, where the choice labels themselves are used as keys for the $structuredValues array (thus preventing duplicates). Happens in Symfony 2.8 as well |
+1 This is preventing upgrading to 2.7 on an app of ours. I have suspected duplicate content being the culprit, this is BC breaking in any case! I have created a minimal test case fwiw: https://gist.github.com/YetiCGN/99085117fb0f6829ccb1 |
I have covered that part with a test, it succeeds. This happens somehow in createView, I suspect a ViewTransformer. Creating a test case for that right now. Edit: Nope, not the ViewTransformer either ... still searching... Edit 2: Found it. It's the fact that without a group_by option set, it defaults to a flipped version of the choices array. That is then taken to render the choices. See https://github.com/symfony/form/blob/master/Extension/Core/Type/ChoiceType.php#L448 |
Related to #15061 |
Here is what I've learned so far:
|
Actually, the real issue seems to be contained in the ChoiceType: Only if the option This is hard to fix, because we would need a new option that is immediately deprecated but also active by default to solve this. Or the ChoiceType should fall back to the deprecated SimpleChoiceList when called with a @webmozart What are your thoughts on this? |
We have the same BC break in our application migrated from 2.3.x => 2.7.2 There is a lot of use case where you can't delete duplicate based on label |
Since there's still no fix here's how we tackled the problem (ugly, yes, but works): in affected forms we append label with object's id like 'UNIQUE:Id' and later strip / UNIQUE:.+$/ from label before rendering it (prefix is at your discretion, we use MongoId so it's quite easy to not strip "real" part of label and we're even omitting prefix). So in general append something unique to label and strip it in Twig later 👶 |
Same for me. We use choices like this
and now it is broken. I think it can be fixed in DefaultChoiceListFactory::addChoiceViewsGroupedBy. Instead of call it with $list->getStructuredValues() it must be called with $list->getOriginalValues() I will prepare PR, will see if it will be work. |
Pull request done. |
+1 |
same problem here, |
This is fixed in the referenced PR. Does the fix work for you? |
…using "choices_as_values" = false (webmozart) This PR was merged into the 2.7 branch. Discussion ---------- [Form] Fixed: Duplicate choice labels are remembered when using "choices_as_values" = false | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15606 | License | MIT | Doc PR | - Commits ------- 1179f07 [Form] Fixed: Duplicate choice labels are remembered when using "choices_as_values" = false
Incorrect/invalid select tag is generated if choices have duplicate content ('Category 4').
Where is option with value="2"?
The text was updated successfully, but these errors were encountered: