mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
fix numeric field for null values
This commit is contained in:
parent
64005bff91
commit
f14e6bae2c
@ -132,7 +132,7 @@ class NumericField extends TextField
|
||||
public function Value()
|
||||
{
|
||||
// Show invalid value back to user in case of error
|
||||
if ($this->value === false) {
|
||||
if ($this->value === null || $this->value === false) {
|
||||
return $this->originalValue;
|
||||
}
|
||||
$formatter = $this->getFormatter();
|
||||
@ -154,6 +154,9 @@ class NumericField extends TextField
|
||||
*/
|
||||
protected function cast($value)
|
||||
{
|
||||
if (strlen($value) === 0) {
|
||||
return null;
|
||||
}
|
||||
if ($this->getScale() === 0) {
|
||||
return (int)$value;
|
||||
}
|
||||
|
@ -127,6 +127,19 @@ class NumericFieldTest extends SapphireTest
|
||||
$this->assertContains('type="text"', $html, 'number type not set');
|
||||
}
|
||||
|
||||
public function testNullSet() {
|
||||
$field = new NumericField('Number');
|
||||
$field->setValue('');
|
||||
$this->assertEquals('', $field->Value());
|
||||
$this->assertNull($field->dataValue());
|
||||
$field->setValue(null);
|
||||
$this->assertNull($field->Value());
|
||||
$this->assertNull($field->dataValue());
|
||||
$field->setValue(0);
|
||||
$this->assertEquals(0, $field->Value());
|
||||
$this->assertEquals(0, $field->dataValue());
|
||||
}
|
||||
|
||||
public function dataForTestSubmittedValue()
|
||||
{
|
||||
return [
|
||||
|
Loading…
x
Reference in New Issue
Block a user