feature #9208 [Form] Add a 'submitted' attribute to the form view (egeloen)
This PR was merged into the master branch.
Discussion
----------
[Form] Add a 'submitted' attribute to the form view
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | symfony/symfony-docs#3029
Basically, the use case of this PR is to determine in the view if a form has been validated by the validator. By default, the valid attribute is true and we can't know if the form has been submitted. Now, we can use `form.vars.submitted && form.vars.valid`.
Commits
-------
a386c74
[Form] Add a 'submitted' attribute to the form view
This commit is contained in:
commit
5130c0317b
@ -97,6 +97,7 @@ class FormType extends BaseType
|
|||||||
'compound' => $form->getConfig()->getCompound(),
|
'compound' => $form->getConfig()->getCompound(),
|
||||||
'method' => $form->getConfig()->getMethod(),
|
'method' => $form->getConfig()->getMethod(),
|
||||||
'action' => $form->getConfig()->getAction(),
|
'action' => $form->getConfig()->getAction(),
|
||||||
|
'submitted' => $form->isSubmitted(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,6 +534,21 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$this->assertFalse($view->vars['valid']);
|
$this->assertFalse($view->vars['valid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testViewSubmittedNotSubmitted()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('form');
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertFalse($view->vars['submitted']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testViewSubmittedSubmitted()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('form');
|
||||||
|
$form->submit(array());
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertTrue($view->vars['submitted']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDataOptionSupersedesSetDataCalls()
|
public function testDataOptionSupersedesSetDataCalls()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('form', null, array(
|
$form = $this->factory->create('form', null, array(
|
||||||
|
Reference in New Issue
Block a user