Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] Improve invalid messages for form types#27142
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
fabpot left a comment
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.
Looks good to me. We should add all these new error messages in translations as well.
| 'divisor' =>1, | ||
| 'currency' =>'EUR', | ||
| 'compound' =>false, | ||
| 'invalid_message' =>'The money is invalid.', |
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.
money amount?
hiddewie commentedMay 18, 2018 • 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.
@fabpot Thank you for the review. I've added your comment for the translation for the money type. As for the translations, do you mean all the files in |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
hiddewie commentedSep 9, 2018
@fabian I've added the translations to the English file. However, I am not sure what the correct precedure is for all the other languages (of which I can only translate 2 myself). |
xabbuh commentedSep 15, 2018
I am not sure that it is a good idea to change the default value for this option for all built-in form types. This means that custom translations in project wouldn't be working anymore after updating to a Symfony version containing this feature. That's not a good DX IMO. |
hiddewie commentedSep 19, 2018
@xabbuh You are right, these changes could be seen as backwards incompatible. What do you propose: close the PR or leave it open until there is a major new version? |
fabpot commentedOct 10, 2018
I didn't thought about the BC issue here. Looks like a deal breaker :( Let's close then. Sorry@hiddewie |
ogizanagi commentedOct 10, 2018
Perhaps we could reopen and find a proper upgrade path? For instance, register a Then, in 5.1, deprecate This seems a lot, but I find this PR valuable. Actually, IMHO, the BC break here is sensible. |
hiddewie commentedOct 12, 2018
@ogizanagi That would be possible! Would an option name of What is the proper precedure for deprecating something in a far future release? Just open a new issue after this PR is merged (if it is merged at all)? |
ogizanagi commentedOct 12, 2018
Actually I don't think we have any specific workflow for this. |
hiddewie commentedOct 21, 2018 • 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.
@ogizanagi I've made some changes. Review is very welcome. The PR has grown considerably in code and also in complexity, but I hope everything works out. Also see the updated description of the PR for some notes on the upgrade path. Mostly what you described. I've enabled the improved messages in most of the tests, to avoid breaking the tests because of the deprecation message. Marking them all as legacy does not seem as a good idea to me. I've made some new tests that check the backwards deprecation notice both for framework and form). |
ogizanagi left a comment
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.
Great work@hiddewie
Note we could set this to true by default for new projects by adding a form recipe.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php OutdatedShow resolvedHide resolved
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/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Resources/translations/validators.en.xlf OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
hiddewie commentedOct 22, 2018 • 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.
@ogizanagi I've processed your comments. Thanks for the input.
|
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| class ValidatorExtensionextends AbstractExtension | ||
| { | ||
| private$validator; | ||
| private$improvedValidationMessages; |
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.
instead of this integration wouldnt setting e.g.static FormType::$legacyErrorMessages = false be simpler? That's something we can get rid of easily in 5.0 (mark it internal): set it from the bundle extension and access it in each form type
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.
That'd be less flexible (as it'll only be global) if you want to update part of your app step by step...but regarding the number of translations to update, that might be an option to consider.
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.
introducing a newimproved_validation_messages form type option, we have to deprecate again in 5.0 and remove in 6.0, is not worth it IMHO
hiddewie commentedNov 10, 2018
@ro0NL@ogizanagi Processed some comments. |
HeahDude left a comment
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.
Thank you for improving this in a BC way!
It would be nice to have other reviews to be sure we cannot improve some wording more before breaking BC later.@weaverryan@javiereguiluz would you mind having a look at this one?
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.
hiddewie commentedNov 19, 2018
@HeahDude I've processed your comments. Didn't think of the types which cannot be invalid. |
HeahDude commentedNov 24, 2018
Thank you@hiddewie! I've reviewed it again and it looks good to me. But we need to adjust some things now that#28731 as been merged. Because the option did not exist in core before, only added by the validator extension (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php#L59). So here's what I spotted so far:
ping@xabbuh what do you think? |
hiddewie commentedDec 30, 2018
@HeahDude Thanks. Processed comment. I'm unsure if I should remove the same code fromhttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php#L117 (I don't think so since any forms with the |
fabpot commentedJan 1, 2019
@hiddewie For this pull request to be merged, you need to rebase it (to remove the merge commits). |
hiddewie commentedJan 2, 2019
@fabpot Done. |
HeahDude left a comment
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.
Thank you! another round of review :)
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/Extension/Validator/Type/FormTypeValidatorExtension.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Resources/translations/validators.en.xlf OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
hiddewie commentedJan 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.
@HeahDude Thanks for the review. I've added a load of tests for the custom validation messages, including the legacy variant. I also noticed that the logic for legacy / non-legacy was flipped in the form types. Has been corrected. Also rebased for new array syntax changes. |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
hiddewie commentedFeb 4, 2019
@xabbuh Done! |
xabbuh commentedApr 6, 2019
Thank you very much for your pull request! As part of the Symfony EU funded hackathon (https://symfony.com/blog/the-symfony-and-api-platform-hackathon-is-coming), we were able to assemble most of the core team and big contributors in one place. Our goal is to finish as many open issues and PRs as possible. Your commits will not be lost and you will therefore get credit for your work. All that will happen is that your commits will be moved to a new PR (see#30931) where all remaining concerns will be addressed. Without your work this would not have been possible. So thank you once again! |
hiddewie commentedApr 7, 2019
No problem, thanks for the work! |
This PR was merged into the 5.2-dev branch.Discussion----------[Form] Improve invalid messages for form types| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets |#27142,#5946| License | MIT| Doc PR | TODOThis merge request is a continuation of#27142.Changes done here:* rebased on master* made the error messages friendlierCommits-------8728927 Improve invalid messages for form types
Uh oh!
There was an error while loading.Please reload this page.
Improvement of#14106. Added
invalid_messagefields to all form types. This gives better errors to users instead of the defaultInvalid value error.Backwards compatibility
After discussion about BC, the following additions have been made:
framework.form.improved_validation_messages(default false) for enabling improved validation messages globally.improved_validation_messageswhich enables improved validation messages for that type.ValidatorExtensionandFormTypeValidatorExtension(default false) to enable/disable the improved validation messages for that extension.Upgrade path
true(enabled) by default.