Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Add ability to clear form errors #27571

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

Closed
wants to merge 2 commits into from
Closed

[Form] Add ability to clear form errors #27571

wants to merge 2 commits into from

Conversation

TerjeBr
Copy link

@TerjeBr TerjeBr commented Jun 10, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets #14060
License MIT
Doc PR symfony/symfony-docs#9908

This PR adds the ability to manually clear form errors, thus improving the DX issue reported in #14060.
This is a copy of PR #14233

Update to latest symfony master
@colinodell
Copy link
Contributor

Thank you for re-creating and re-submitting my old commit! 👍

*
* @return FormInterface The form instance
*/
public function clearErrors($deep = false);
Copy link
Contributor

@linaori linaori Jun 11, 2018

Choose a reason for hiding this comment

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

I don't think this will be possible. You'll have to make this work for 4.x as well and as is, it's a BC break. Probably requires a new interface, which can be merged in this interface in 5.0.

Copy link
Author

@TerjeBr TerjeBr Jun 11, 2018

Choose a reason for hiding this comment

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

Do you mean I should create something like FormClearErrorsInterface and make Form implement that?

If we want to merge it into FormInterface in 5.0, does that mean the FormClearErrorsInterface should be marked as deprecated right away, so that people will be aware that it goes away in version 5.0?

I have not done something like this before, so that is why I would apreciate some guideance in how to do it. Thanks.

Copy link
Author

Choose a reason for hiding this comment

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

Also @dosten wrote in #14233 (comment) that the BC break would not be a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also @dosten wrote in #14233 (comment) that the BC break would not be a problem.

The BC promise states that adding a new method is not acceptable http://symfony.com/doc/current/contributing/code/bc.html#changing-interfaces

Copy link
Contributor

@jvasseur jvasseur Jun 11, 2018

Choose a reason for hiding this comment

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

@TerjeBr The comment you linked dates from 2015, since then the concept of @api interface was removed and we now consider every class as part of the public API (#15977, symfony/symfony-docs#5735). This means we can't add methods to any interface.

@TerjeBr
Copy link
Author

TerjeBr commented Jun 11, 2018

Please correct me if I am misstaken, but is the FormInterface something symfony users would implement?

Is this interfece not more kind of "internal" to the Symfony framework?

@pierredup
Copy link
Contributor

Only if an interface is marked as @internal, then it's not meant to be implemented (as is not part of the BC promise. See http://symfony.com/doc/current/contributing/code/bc.html#using-our-interfaces for more information)

@nicolas-grekas nicolas-grekas added this to the next milestone Jun 11, 2018
@TerjeBr
Copy link
Author

TerjeBr commented Jun 11, 2018

I am trying to find a way forward here. Is it reasonable to want to mark FormInterface as @internal? Or is that out of the question? Who else than Symfony maintainers implements the FormInterface?

@TerjeBr
Copy link
Author

TerjeBr commented Jun 11, 2018

Or if I do as @iltar suggested, add a new interface, should that interface be created with the tag @deprecated if we aim to remove it again in version 5.0?

@javiereguiluz
Copy link
Member

Let's ping our Symfony Form expert @vudaltsov to see if he can spot any issue here (besides the interface issue mentioned by Iltar).

@vudaltsov
Copy link
Contributor

This PR can be closed in favor of #27580.

@@ -10,6 +10,7 @@ CHANGELOG
* deprecated the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`
* added `input=datetime_immutable` to DateType, TimeType, DateTimeType
* added `rounding_mode` option to MoneyType
* added `FormInterface::clearErrors()` method
Copy link
Member

Choose a reason for hiding this comment

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

we cannot do this in a minor release as it is a BC break

*
* @return FormInterface The form instance
*/
public function clearErrors($deep = false);
Copy link
Member

Choose a reason for hiding this comment

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

This is a BC break that needs to be reverted.

/**
* {@inheritdoc}
*/
public function clearErrors($deep = false)
Copy link
Member

Choose a reason for hiding this comment

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

public function clearErrors(bool $deep = false): void

@xabbuh
Copy link
Member

xabbuh commented Jun 19, 2018

Ah sorry, I missed #27580. So I am going to close here in favour of it. Thank you @TerjeBr for bootstrapping the work.

@xabbuh xabbuh closed this Jun 19, 2018
fabpot added a commit that referenced this pull request Jun 25, 2018
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
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants