mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
parent
b38942b3fa
commit
fd630a99b0
@ -11,7 +11,26 @@ use SilverStripe\Forms\NumericField;
|
||||
class DBDecimal extends DBField
|
||||
{
|
||||
|
||||
protected $wholeSize, $decimalSize, $defaultValue;
|
||||
/**
|
||||
* Whole number size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $wholeSize = 9;
|
||||
|
||||
/**
|
||||
* Decimal scale
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $decimalSize = 2;
|
||||
|
||||
/**
|
||||
* Default value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $defaultValue = 0;
|
||||
|
||||
/**
|
||||
* Create a new Decimal field.
|
||||
@ -27,7 +46,6 @@ class DBDecimal extends DBField
|
||||
$this->decimalSize = is_int($decimalSize) ? $decimalSize : 2;
|
||||
|
||||
$this->defaultValue = number_format((float) $defaultValue, $decimalSize);
|
||||
;
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
@ -84,7 +102,8 @@ class DBDecimal extends DBField
|
||||
*/
|
||||
public function scaffoldFormField($title = null, $params = null)
|
||||
{
|
||||
return new NumericField($this->name, $title);
|
||||
return NumericField::create($this->name, $title)
|
||||
->setScale($this->decimalSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,12 +3,16 @@
|
||||
namespace SilverStripe\ORM\Tests;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\FieldType\DBDecimal;
|
||||
|
||||
class DecimalTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected static $fixture_file = 'DecimalTest.yml';
|
||||
|
||||
/**
|
||||
* @var DecimalTest\TestObject
|
||||
*/
|
||||
protected $testDataObject;
|
||||
|
||||
protected static $extra_dataobjects = array(
|
||||
@ -56,4 +60,15 @@ class DecimalTest extends SapphireTest
|
||||
'Default value for Decimal type is set to 4'
|
||||
);
|
||||
}
|
||||
|
||||
public function testScaffoldFormField()
|
||||
{
|
||||
/** @var DBDecimal $decimal */
|
||||
$decimal = $this->testDataObject->dbObject('MyDecimal2');
|
||||
$field = $decimal->scaffoldFormField('The Decimal');
|
||||
$this->assertEquals(3, $field->getScale());
|
||||
$field->setValue(1.9999);
|
||||
$this->assertEquals(1.9999, $field->dataValue());
|
||||
$this->assertEquals('2.000', $field->Value());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user