-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add ability to clear form errors #27571
8000New 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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -795,6 +795,22 @@ public function getErrors($deep = false, $flatten = true) | |
return new FormErrorIterator($this, $errors); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function clearErrors($deep = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
$this->errors = array(); | ||
// Clear also the errors of nested forms | ||
if ($deep) { | ||
foreach ($this as $child) { | ||
$child->clearErrors(true); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,15 @@ public function all(); | |
*/ | ||
public function getErrors($deep = false, $flatten = true); | ||
|
||
/** | ||
* Removes all the errors of this form. | ||
* | ||
* @param bool $deep Whether to remove errors of child forms as well | ||
* | ||
* @return FormInterface The form instance | ||
*/ | ||
public function clearErrors($deep = false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean I should create something like If we want to merge it into I have not done something like this before, so that is why I would apreciate some guideance in how to do it. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment.
The BC promise states that adding a new method is not acceptable http://symfony.com/doc/current/contributing/code/bc.html#changing-interfaces There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a BC break that needs to be reverted. |
||
|
||
/** | ||
* Updates the form with default data. | ||
* | ||
|
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 cannot do this in a minor release as it is a BC break