mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Bugfix NumericField shows (none) for 0 on readonly
This commit is contained in:
parent
bd23ff0a3a
commit
082c49c1b5
@ -44,4 +44,27 @@ class NumericField extends TextField {
|
|||||||
public function dataValue() {
|
public function dataValue() {
|
||||||
return (is_numeric($this->value)) ? $this->value : 0;
|
return (is_numeric($this->value)) ? $this->value : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a readonly version of this field
|
||||||
|
*/
|
||||||
|
public function performReadonlyTransformation() {
|
||||||
|
$field = new NumericField_Readonly($this->name, $this->title, $this->value);
|
||||||
|
$field->setForm($this->form);
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NumericField_Readonly extends ReadonlyField{
|
||||||
|
|
||||||
|
public function performReadonlyTransformation() {
|
||||||
|
return clone $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Value() {
|
||||||
|
return Convert::raw2xml($this->value ?
|
||||||
|
"$this->value" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,5 +33,8 @@ class NumericFieldTest extends SapphireTest {
|
|||||||
|
|
||||||
$field->setValue('12.00');
|
$field->setValue('12.00');
|
||||||
$this->assertFalse($field->validate($validator));
|
$this->assertFalse($field->validate($validator));
|
||||||
|
|
||||||
|
$field->setValue(0);
|
||||||
|
$this->assertRegExp("#<span[^>]+>\s*0\s*<\/span>#", "".$field->performReadonlyTransformation()->Field()."");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user