mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7103 from dnadesign/fix-numericfield-null
This commit is contained in:
commit
2c5e237a93
@ -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,20 @@ 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…
Reference in New Issue
Block a user