Merge pull request #4788 from christopherdarling/patch-5

FIX: for ConfirmedPasswordField validation
This commit is contained in:
Daniel Hensby 2015-11-23 07:58:24 +00:00
commit e0d7400aea
2 changed files with 22 additions and 1 deletions

View File

@ -264,6 +264,7 @@ class ConfirmedPasswordField extends FormField {
} else { } else {
if($value || (!$value && $this->canBeEmpty)) { if($value || (!$value && $this->canBeEmpty)) {
$this->value = $value; $this->value = $value;
$this->confirmValue = $value;
} }
} }
@ -273,7 +274,7 @@ class ConfirmedPasswordField extends FormField {
->setValue($this->value); ->setValue($this->value);
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]') $this->children->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->value); ->setValue($this->confirmValue);
} }
return $this; return $this;

View File

@ -72,4 +72,24 @@ class ConfirmedPasswordFieldTest extends SapphireTest {
$this->assertFalse($field->validate($validator)); $this->assertFalse($field->validate($validator));
} }
public function testFormValidation() {
$form = new Form(
new Controller(),
'Form',
new FieldList($field = new ConfirmedPasswordField('Password')),
new FieldList()
);
$form->loadDataFrom(array(
'Password' => array(
'_Password' => '123',
'_ConfirmPassword' => '999',
)
));
$this->assertEquals('123', $field->children->first()->Value());
$this->assertEquals('999', $field->children->last()->Value());
$this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
}
} }