Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
hiddewie wants to merge5 commits intosymfony:masterfromhiddewie:better-invalid-messages
Closed

[Form] Improve invalid messages for form types#27142

hiddewie wants to merge5 commits intosymfony:masterfromhiddewie:better-invalid-messages

Conversation

@hiddewie
Copy link
Contributor

@hiddewiehiddewie commentedMay 3, 2018
edited
Loading

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#5946
LicenseMIT

Improvement of#14106. Addedinvalid_message fields 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:

  • An framework optionframework.form.improved_validation_messages (default false) for enabling improved validation messages globally.
  • A form validation extension optionimproved_validation_messages which enables improved validation messages for that type.
  • An added parameter for theValidatorExtension andFormTypeValidatorExtension (default false) to enable/disable the improved validation messages for that extension.
  • All the form types now check for the enabled opt-in configuration for improved validation messages. Otherwise, the previous default is used which should be the original message.

Upgrade path

  • These changes should be backwards compatible.
  • For Symfony 5.0, the improved validation messages configuration in the framework and form should betrue (enabled) by default.
  • The options can be deprecated entirely in Symfony 5.1, to be removed in Symfony 6.0.

Koc and ogizanagi reacted with thumbs up emoji
@nicolas-grekasnicolas-grekas added this to thenext milestoneMay 3, 2018
@nicolas-grekasnicolas-grekas changed the titleImprove invalid messages for form types[Form] Improve invalid messages for form typesMay 4, 2018
Copy link
Member

@fabpotfabpot left a 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.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

money amount?

@hiddewie
Copy link
ContributorAuthor

hiddewie commentedMay 18, 2018
edited
Loading

@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 insrc\Symfony\Component\Form\Resources\translations\validators.*.xlf? Of course I can add the translation keys there, but I cannot do translations in all those different languages (except Dutch and maybe German).

@hiddewie
Copy link
ContributorAuthor

@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
Copy link
Member

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
Copy link
ContributorAuthor

@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
Copy link
Member

I didn't thought about the BC issue here. Looks like a deal breaker :( Let's close then. Sorry@hiddewie

@fabpotfabpot closed thisOct 10, 2018
@ogizanagi
Copy link
Contributor

Perhaps we could reopen and find a proper upgrade path?

For instance, register abetter_invalid_messages or [INSERT_BETTER_NAME] option fromFormTypeValidatorExtension. Then if, ifbetter_invalid_messages isfalse, trigger a deprecation.
Aframework.form.better_invalid_messages framework option can be used to configure the default value used byFormTypeValidatorExtension globally, so any new project can be free of deprecations.

Then, in 5.1, deprecatebetter_invalid_messages andframework.form.better_invalid_messages to be removed in 6.0 as it won't have any effect anymore.

This seems a lot, but I find this PR valuable. Actually, IMHO, the BC break here is sensible.

@fabpotfabpot reopened thisOct 10, 2018
@hiddewie
Copy link
ContributorAuthor

@ogizanagi That would be possible! Would an option name ofimproved_validation_messages work?

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
Copy link
Contributor

What is the proper procedure 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.
An issue could be great, but can be easily forgotten.
We could open a note on a project inhttps://github.com/symfony/symfony/projects in order to not forget this, but this kind of situation doesn't happen really often.
But I'm confident anyone doing the PR to remove the BC layer in 5.0 will think about doing one to deprecate it in 5.1 :)

@hiddewie
Copy link
ContributorAuthor

hiddewie commentedOct 21, 2018
edited
Loading

@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).

Copy link
Contributor

@ogizanagiogizanagi left a 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.

@hiddewie
Copy link
ContributorAuthor

hiddewie commentedOct 22, 2018
edited
Loading

@ogizanagi I've processed your comments. Thanks for the input.

  • I will look into updating the receipe.
  • I also want to write tests for at least some form types in the Core extension and using the Type Validator Extension which check the old and the new error messages.
  • I have to update the changelog files for all these new framework/form parameters/options.

class ValidatorExtensionextends AbstractExtension
{
private$validator;
private$improvedValidationMessages;
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
ContributorAuthor

@ro0NL@ogizanagi Processed some comments.

Copy link
Contributor

@HeahDudeHeahDude left a 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?

@hiddewie
Copy link
ContributorAuthor

@HeahDude I've processed your comments. Didn't think of the types which cannot be invalid.

@HeahDude
Copy link
Contributor

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
Copy link
ContributorAuthor

@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 theconstraints option are excluded from the new extension).

@fabpot
Copy link
Member

@hiddewie For this pull request to be merged, you need to rebase it (to remove the merge commits).

@hiddewie
Copy link
ContributorAuthor

@fabpot Done.

Copy link
Contributor

@HeahDudeHeahDude left a 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 :)

@hiddewie
Copy link
ContributorAuthor

hiddewie commentedJan 26, 2019
edited
Loading

@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.

@hiddewie
Copy link
ContributorAuthor

@xabbuh Done!

@xabbuh
Copy link
Member

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!

HeahDude and hiddewie reacted with thumbs up emoji

@hiddewie
Copy link
ContributorAuthor

No problem, thanks for the work!

@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
xabbuh added a commit that referenced this pull requestJul 10, 2020
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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot requested changes

@xabbuhxabbuhxabbuh requested changes

+3 more reviewers

@ro0NLro0NLro0NL left review comments

@ogizanagiogizanagiogizanagi left review comments

@HeahDudeHeahDudeHeahDude requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

8 participants

@hiddewie@xabbuh@fabpot@ogizanagi@HeahDude@ro0NL@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp