mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fix the broken perform readonly transformation which was always showing NO (#6453)
This commit is contained in:
parent
fd649a418d
commit
dee3939cf7
@ -50,7 +50,7 @@ class CheckboxField extends FormField {
|
||||
* Returns a readonly version of this field
|
||||
*/
|
||||
function performReadonlyTransformation() {
|
||||
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
|
||||
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
|
||||
$field->setForm($this->form);
|
||||
return $field;
|
||||
}
|
||||
@ -74,8 +74,8 @@ class CheckboxField_Readonly extends ReadonlyField {
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
function setValue($val) {
|
||||
$this->value = (int)($val) ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No');
|
||||
function Value() {
|
||||
return Convert::raw2xml($this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
|
||||
}
|
||||
|
||||
}
|
@ -118,6 +118,23 @@ class CheckboxFieldTest extends SapphireTest {
|
||||
$article->delete();
|
||||
}
|
||||
|
||||
function testReadonlyCheckboxField() {
|
||||
// Test 1: a checked checkbox goes to "Yes"
|
||||
$field1 = new CheckboxField('IsChecked', 'Checked');
|
||||
$field1->setValue('on');
|
||||
$this->assertEquals(_t('CheckboxField.YES', 'Yes'), trim(strip_tags($field1->performReadonlyTransformation()->Field())));
|
||||
|
||||
// Test 2: an checkbox with the value set to false to "No"
|
||||
$field2 = new CheckboxField('IsChecked', 'Checked');
|
||||
$field2->setValue(false);
|
||||
$this->assertEquals(_t('CheckboxField.NO', 'No'), trim(strip_tags($field2->performReadonlyTransformation()->Field())));
|
||||
|
||||
// Test 3: an checkbox with no value ever set goes to "No"
|
||||
$field3 = new CheckboxField('IsChecked', 'Checked');
|
||||
$this->assertEquals(_t('CheckboxField.NO', 'No'), trim(strip_tags($field3->performReadonlyTransformation()->Field())));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
class CheckboxFieldTest_Article extends DataObject implements TestOnly {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user