[Form] Added valid attribute to a FormView

This commit is contained in:
Kevin Dew 2012-05-22 12:44:27 +01:00
parent fc34ed1f86
commit e92212ac13
2 changed files with 18 additions and 0 deletions

View File

@ -110,6 +110,7 @@ class FormType extends AbstractType
->set('full_name', $fullName)
->set('read_only', $readOnly)
->set('errors', $form->getErrors())
->set('valid', $form->isBound() ? $form->isValid() : true)
->set('value', $form->getClientData())
->set('disabled', $form->isDisabled())
->set('required', $form->isRequired())

View File

@ -16,6 +16,7 @@ use Symfony\Component\Form\Form;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Tests\Fixtures\Author;
use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer;
use Symfony\Component\Form\FormError;
class FormTest_AuthorWithoutRefSetter
{
@ -604,4 +605,20 @@ class FormTypeTest extends TypeTestCase
$this->assertEquals(new PropertyPath('foo'), $form->getPropertyPath());
$this->assertFalse($form->getConfig()->getMapped());
}
public function testViewValidUnbound()
{
$form = $this->factory->create('form');
$view = $form->createView();
$this->assertTrue($view->get('valid'));
}
public function testViewNotValidBound()
{
$form = $this->factory->create('form');
$form->bind(array());
$form->addError(new FormError('An error'));
$view = $form->createView();
$this->assertFalse($view->get('valid'));
}
}