Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Form] Add "is empty callback" to form config#32747
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We also need to trigger some deprecations if implementations of theFormConfigInterface
andFormConfigBuilderInterface
do not implement the new methods. And those changes must be documented in theCHANGELOG.md
file of the Form component as well as in theUPGRADE-4.4.md
andUPGRADE-5.0.md
files.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
fancyweb commentedJul 26, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Nice point, let's throw a deprecation in the Is the BC break on |
I was thinking about that as well. Right now I couldn't come up with anything that used to work before and would now break. And our test suite seems to confirm this. But we should try hard to think about potential use cases that could break with this change. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
I wonder if it might be useful to add a dedicated option to set it up, maybe an |
I was actually rather thinking about whether we should mark the new method as internal instead as I am not really sure that this is an extension point we should expose that much. I think usage of this in userland is quite limited and it increases risk by forms not working correctly if not used correctly. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Using an option would mean that it could not exist (in custom form type not extending
I agree that userland usage is limited. However, I'm against making it internal because it adds a nice customisable behavior if well used. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
… (fancyweb)This PR was merged into the 4.3 branch.Discussion----------Sync "not implementing the method" deprecations messages| Q | A| ------------- | ---| Branch? | 4.3| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Suggested in#32747 (comment)Useful for consistency and for future reference for similar messages.Commits-------f6fae1c Sync "not implementing the method" deprecations messages
… (fancyweb)This PR was merged into the 4.3 branch.Discussion----------Sync "not implementing the method" deprecations messages| Q | A| ------------- | ---| Branch? | 4.3| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Suggested insymfony/symfony#32747 (comment)Useful for consistency and for future reference for similar messages.Commits-------f6fae1c361 Sync "not implementing the method" deprecations messages
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
f4d1c75
to24e199d
CompareUh oh!
There was an error while loading.Please reload this page.
7c430bd
to899a2b9
Compare899a2b9
to32cd54c
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
please rebase
Uh oh!
There was an error while loading.Please reload this page.
32cd54c
tocc73e52
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Comments discussed with@fancyweb on Slack, we can ignore them, PR is good to go. |
Thank you@fancyweb. |
This PR was merged into the 5.1-dev branch.Discussion----------[Form] Add "is empty callback" to form config| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#31572 for 4.4+| License | MIT| Doc PR | -This PR introduces a new feature that allow to resolve a bug.Currently, the `isEmpty()` behavior of the `Form` class is the same whatever its configuration. That prevents us to specify a different behavior by form type.But I think that some form types should have dedicated empty values. For example, the `CheckboxType` model data either resolves to `true` (checked) or `false` (unchecked). But `false` is not an empty value in the `Form::isEmpty()` method, so a `CheckboxType` form can never be empty. `false` should not be in that list because for other form types, it's perfectly fine that it's not considered as an empty value.The problem is better seen in#31572 with a `ChoiceType` that is never considered as empty (when no radio button is checked).Being able to specify the "is empty" behavior by form type would also allow users to define their own logic in their custom form types + probably define it ourselves in all our form types in order to get rid of the default common behavior.Commits-------7bfc27e [Form] Add "is empty callback" to form config
…ncyweb)This PR was merged into the 3.4 branch.Discussion----------[Form] Handle false as empty value on expanded choices| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |#31572| License | MIT| Doc PR | -This is the 3.4 version of#32747. The tests are the same. The added code has to be removed from master (if accepted).Commits-------1a366bc [Form] Handle false as empty value on expanded choices
Uh oh!
There was an error while loading.Please reload this page.
This PR introduces a new feature that allow to resolve a bug.
Currently, the
isEmpty()
behavior of theForm
class is the same whatever its configuration. That prevents us to specify a different behavior by form type.But I think that some form types should have dedicated empty values. For example, the
CheckboxType
model data either resolves totrue
(checked) orfalse
(unchecked). Butfalse
is not an empty value in theForm::isEmpty()
method, so aCheckboxType
form can never be empty.false
should not be in that list because for other form types, it's perfectly fine that it's not considered as an empty value.The problem is better seen in#31572 with a
ChoiceType
that is never considered as empty (when no radio button is checked).Being able to specify the "is empty" behavior by form type would also allow users to define their own logic in their custom form types + probably define it ourselves in all our form types in order to get rid of the default common behavior.