-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] Ability to clear form errors #9916
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
[Form] Ability to clear form errors #9916
Conversation
components/form.rst
Outdated
Clearing Form Errors | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Any errors can be manually cleared using the :method:`Symfony\\Component\\Form\\ClearableErrorInterface::clearErrors` method. This is useful when you'd like to validate the form without showing validation errors to the user (i.e. during a partial AJAX submission or :doc:`dynamic form modification </form/dynamic_form_modification>`). |
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.
ClearableErrorsInterface
? s
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.
Good catch! I renamed the interface but forgot to update the docs. Fixed and amended!
components/form.rst
Outdated
Clearing Form Errors | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Any errors can be manually cleared using the :method:`Symfony\\Component\\Form\\ClearableErrorsInterface::clearErrors` method. This is useful when you'd like to validate the form without showing validation errors to the user (i.e. during a partial AJAX submission or :doc:`dynamic form modification </form/dynamic_form_modification>`). |
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 should precise that clearing the errors makes the form valid. So clearErrors()
should be called after testing if the form is valid or at least not rely on its state.
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.
I have added a new sentence to clarify that. Thanks!
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.
Thanks!
This PR was squashed before being merged into the 4.2-dev branch (closes #27580). Discussion ---------- [Form] Add ability to clear form errors | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14060 | License | MIT | Doc PR | symfony/symfony-docs#9916 This PR adds the ability to manually clear form errors, thus improving the DX issue reported in #14060. Unlike my original approach in #14233 and #27571 which break BC, this adds a new `ClearableErrorInterface` which `Form` implements. (`Button` does not implement it because buttons can't have errors.) Commits ------- 9eb755c07f [Form] Add ability to clear form errors
This PR was squashed before being merged into the 4.2-dev branch (closes #27580). Discussion ---------- [Form] Add ability to clear form errors | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14060 | License | MIT | Doc PR | symfony/symfony-docs#9916 This PR adds the ability to manually clear form errors, thus improving the DX issue reported in #14060. Unlike my original approach in #14233 and #27571 which break BC, this adds a new `ClearableErrorInterface` which `Form` implements. (`Button` does not implement it because buttons can't have errors.) Commits ------- 9eb755c [Form] Add ability to clear form errors
@colinodell thanks for improving Forms DX with this new feature and thanks for providing the docs too. Everything is perfectly explained! |
…uiluz) This PR was merged into the master branch. Discussion ---------- [Form] Ability to clear form errors Documenting the new feature proposed in symfony/symfony#27580 Commits ------- f07f536 Wrap long lines and add the versionadded directive 7a4465d Clarify that clearing errors makes the form valid d4143f1 [Form] Ability to clear form errors
Documenting the new feature proposed in symfony/symfony#27580