mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Fix bug when confirmed password is changed but not the password. (#9012)
In this case the confirmed password field is not reflected. It’s
unclear how often this situation would arise outside of test scenarios,
but may come up if $form->loadDataFrom() is called more than once.
Fixes #2496 (it’s a minor issue but I think this is why Dan flagged it
as a regression). Originally introduced as part of Dan’s initial fix
at 2a6f1f1949
.
This commit is contained in:
parent
65f9951c5e
commit
654156d46d
@ -341,6 +341,7 @@ class ConfirmedPasswordField extends FormField
|
|||||||
|
|
||||||
//store this for later
|
//store this for later
|
||||||
$oldValue = $this->value;
|
$oldValue = $this->value;
|
||||||
|
$oldConfirmValue = $this->confirmValue;
|
||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$this->value = $value['_Password'];
|
$this->value = $value['_Password'];
|
||||||
@ -364,7 +365,8 @@ class ConfirmedPasswordField extends FormField
|
|||||||
if ($oldValue != $this->value) {
|
if ($oldValue != $this->value) {
|
||||||
$this->getChildren()->fieldByName($this->getName() . '[_Password]')
|
$this->getChildren()->fieldByName($this->getName() . '[_Password]')
|
||||||
->setValue($this->value);
|
->setValue($this->value);
|
||||||
|
}
|
||||||
|
if ($oldConfirmValue != $this->confirmValue) {
|
||||||
$this->getChildren()->fieldByName($this->getName() . '[_ConfirmPassword]')
|
$this->getChildren()->fieldByName($this->getName() . '[_ConfirmPassword]')
|
||||||
->setValue($this->confirmValue);
|
->setValue($this->confirmValue);
|
||||||
}
|
}
|
||||||
|
@ -148,12 +148,34 @@ class ConfirmedPasswordFieldTest extends SapphireTest
|
|||||||
$form->loadDataFrom([
|
$form->loadDataFrom([
|
||||||
'Password' => [
|
'Password' => [
|
||||||
'_Password' => '123',
|
'_Password' => '123',
|
||||||
'_ConfirmPassword' => '999',
|
'_ConfirmPassword' => '',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('123', $field->children->first()->Value());
|
$this->assertEquals('123', $field->children->first()->Value());
|
||||||
$this->assertEquals('999', $field->children->last()->Value());
|
$this->assertEmpty($field->children->last()->Value());
|
||||||
|
$this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
|
||||||
|
|
||||||
|
$form->loadDataFrom([
|
||||||
|
'Password' => [
|
||||||
|
'_Password' => '123',
|
||||||
|
'_ConfirmPassword' => 'abc',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals('123', $field->children->first()->Value());
|
||||||
|
$this->assertEquals('abc', $field->children->last()->Value());
|
||||||
|
$this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
|
||||||
|
|
||||||
|
$form->loadDataFrom([
|
||||||
|
'Password' => [
|
||||||
|
'_Password' => '',
|
||||||
|
'_ConfirmPassword' => 'abc',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEmpty($field->children->first()->Value());
|
||||||
|
$this->assertEquals('abc', $field->children->last()->Value());
|
||||||
$this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
|
$this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user