Deprecate using Form::isValid() with an unsubmitted form
This commit is contained in:
parent
22f7ed7d9e
commit
2c3a7cc532
|
@ -7,6 +7,28 @@ DependencyInjection
|
|||
* Calling `get()` on a `ContainerBuilder` instance before compiling the
|
||||
container is deprecated and will throw an exception in Symfony 4.0.
|
||||
|
||||
Form
|
||||
----
|
||||
|
||||
* Calling `isValid()` on a `Form` instance before submitting it
|
||||
is deprecated and will throw an exception in Symfony 4.0.
|
||||
|
||||
Before:
|
||||
|
||||
```php
|
||||
if ($form->isValid()) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```php
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Validator
|
||||
---------
|
||||
|
||||
|
|
|
@ -42,6 +42,25 @@ Form
|
|||
* Caching of the loaded `ChoiceListInterface` in the `LazyChoiceList` has been removed,
|
||||
it must be cached in the `ChoiceLoaderInterface` implementation instead.
|
||||
|
||||
* Calling `isValid()` on a `Form` instance before submitting it is not supported
|
||||
anymore and raises an exception.
|
||||
|
||||
Before:
|
||||
|
||||
```php
|
||||
if ($form->isValid()) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```php
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
FrameworkBundle
|
||||
---------------
|
||||
|
||||
|
|
|
@ -724,6 +724,8 @@ class Form implements \IteratorAggregate, FormInterface
|
|||
public function isValid()
|
||||
{
|
||||
if (!$this->submitted) {
|
||||
@trigger_error('Call Form::isValid() with an unsubmitted form is deprecated since version 3.2 and will throw an exception in 4.0. Use Form::isSubmitted() before Form::isValid() instead.', E_USER_DEPRECATED);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
|
|||
/**
|
||||
* Returns whether the form and all children are valid.
|
||||
*
|
||||
* If the form is not submitted, this method always returns false.
|
||||
* If the form is not submitted, this method always returns false (but will throw an exception in 4.0).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Symfony\Component\Form\Tests;
|
||||
|
||||
use Symfony\Bridge\PhpUnit\ErrorAssert;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
@ -315,7 +316,9 @@ class SimpleFormTest extends AbstractFormTest
|
|||
|
||||
public function testNotValidIfNotSubmitted()
|
||||
{
|
||||
ErrorAssert::assertDeprecationsAreTriggered(array('Call Form::isValid() with an unsubmitted form'), function () {
|
||||
$this->assertFalse($this->form->isValid());
|
||||
});
|
||||
}
|
||||
|
||||
public function testNotValidIfErrors()
|
||||
|
|
Reference in New Issue