-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Looks good to me. We should add all these new error messages in translations as well.
@@ -58,6 +58,7 @@ public function configureOptions(OptionsResolver $resolver) | |||
'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?
@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 |
src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php
Outdated
Show resolved
Hide resolved
@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). |
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. |
@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? |
I didn't thought about the BC issue here. Looks like a deal breaker :( Let's close then. Sorry @hiddewie |
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. |
@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)? |
Actually I don't think we have any specific workflow for this. |
@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). |
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.
src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Resources/translations/validators.en.xlf
Outdated
Show resolved
Hide resolved
@ogizanagi I've processed your comments. Thanks for the input.
|
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php
Outdated
Show resolved
Hide resolved
@@ -25,9 +25,12 @@ | |||
class ValidatorExtension extends 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 new improved_validation_messages
form type option, we have to deprecate again in 5.0 and remove in 6.0, is not worth it IMHO
@ro0NL @ogizanagi Processed some comments. |
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?
@HeahDude I've processed your comments. Didn't think of the types which cannot be invalid. |
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? |
@HeahDude Thanks. Processed comment. I'm unsure if I should remove the same code from https://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 |
@hiddewie For this pull request to be merged, you need to rebase it (to remove the merge commits). |
@fabpot Done. |
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 :)
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
Show resolved
Hide resolved
src/Symfony/Component/Form/Resources/translations/validators.en.xlf
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Tests/Extension/Core/Type/BirthdayTypeTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
Outdated
Show resolved
Hide resolved
@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
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
Outdated
Show resolved
Hide resolved
@xabbuh Done! |
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! |
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 | TODO This merge request is a continuation of #27142. Changes done here: * rebased on master * made the error messages friendlier Commits ------- 8728927 Improve invalid messages for form types
Improvement of #14106. Added
invalid_message
fields to all form types. This gives better errors to users instead of the default Invalid 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_messages
which enables improved validation messages for that type.ValidatorExtension
andFormTypeValidatorExtension
(default false) to enable/disable the improved validation messages for that extension.Upgrade path
true
(enabled) by default.