Navigation Menu

Skip to content

Commit

Permalink
[Form] Changed semantics of "always_empty" option in PasswordField
Browse files Browse the repository at this point in the history
If the option is true, the password is never written into the input field's value. If it is false, it is only written into the input field's value after submitting a form with errors.

The default value for "always_empty" is true.
  • Loading branch information
Bernhard Schussek authored and fabpot committed Dec 18, 2010
1 parent a6e414f commit cd64046
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Component/Form/PasswordField.php
Expand Up @@ -28,10 +28,12 @@ protected function configure()
parent::configure();
}

/**
* {@inheritDoc}
*/
public function getDisplayedData()
{
// TESTME
return $this->getOption('always_empty') && !$this->isBound()
return $this->getOption('always_empty') || !$this->isBound()
? ''
: parent::getDisplayedData();
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Symfony/Tests/Component/Form/PasswordFieldTest.php
@@ -0,0 +1,41 @@
<?php

namespace Symfony\Tests\Component\Form;

/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Symfony\Component\Form\PasswordField;

class PasswordFieldTest extends \PHPUnit_Framework_TestCase
{
public function testGetDisplayedData()
{
$field = new PasswordField('name');
$field->setData('before');

$this->assertSame('', $field->getDisplayedData());

$field->bind('after');

$this->assertSame('', $field->getDisplayedData());
}

public function testGetDisplayedDataWithAlwaysEmptyDisabled()
{
$field = new PasswordField('name', array('always_empty' => false));
$field->setData('before');

$this->assertSame('', $field->getDisplayedData());

$field->bind('after');

$this->assertSame('after', $field->getDisplayedData());
}
}

0 comments on commit cd64046

Please sign in to comment.