-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2] [Form] Empty value missing for expanded single-choice field with required set to false #3154
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
Actually you will not have a default value even if you set |
What do you mean with an entry for the empty value? So far, the behavior looks OK for me, not a bug. |
@bschussek ping |
@klaussilveira There should be a radio button like this:
where "Empty" corresponds to the value of the "empty_value" option. |
So where are we with this? if i have a entity field with expanded set to true, and required to false, even adding empty_value manually does not give me the empty ("no selection") radio. Which means if the use accidentally selects he cannot unselect or select a blank option anymore. This is critical bug, 2.1 should at least get an option where explicitly setting empty value makes it show up. |
This is not solved yet. I tried to solve it once and I remember that it was not easy. If you need a quick solution, I'd hardcode an empty radio button in your Twig template. |
@bschussek it seems to me that in the case of Fixing this and adding the same empty value handling in the field definitions should get us a empty radio. Or am overlooking some core aspect of this? |
@rdohms Yes, you are overlooking that the way that the options are generated for expanded fields works completely differently than for collapsed field. The check you are quoting is a safeguard because (even if the check is changed) it won't work anyway. |
Any news on this? |
Fixed in the referenced PR. |
This PR was merged into the master branch. Discussion ---------- [Form] Added radio button for empty value to expanded single-choice fields | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #3154 | License | MIT | Doc PR | symfony/symfony-docs#2605 Commits ------- 7933971 [Form] Added radio button for empty value to expanded single-choice fields
Maybe I misunderstood the usage of the radio button in my use case: $builder
->add('windowMaterialId', 'entity', array(
'class' => 'Acme\AppBundle\Entity\WindowMaterial',
'expanded' => true,
'required' => true,
))
: This will render two choices with the values In this case I want only two buttons - the ones with the choices. But I don't want any choice pre-selected and I don't want an additional "Please Choose" choice. I tried several variations with the Is this not possible or a wrong usage for a radio button - do you recommend a simple |
@webdevilopers the rpe-selected choice will be set based on the data in the object bound to the form. If the property On a side note, naming the property |
Thanks @stof . I am refactoring a legacy form and yet I couldn't change the naming in production! ;) Indeed when I started again on the form this morning I no longer experienced the mentioned pre-selection. The only thing I recognized is that setting |
When creating an expanded, single-choice field that is not required
an entry for the empty value should be added, but is not.
The text was updated successfully, but these errors were encountered: