mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
parents-merge 33066 - Improved support for decimal/currency saving
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45038 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ae388c7d54
commit
5d6a4df183
@ -24,6 +24,15 @@ class Decimal extends DBField {
|
|||||||
|
|
||||||
function requireField() {
|
function requireField() {
|
||||||
DB::requireField($this->tableName, $this->name, "decimal($this->wholeSize,$this->decimalSize)");
|
DB::requireField($this->tableName, $this->name, "decimal($this->wholeSize,$this->decimalSize)");
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveInto() {
|
||||||
|
$fieldName = $this->name;
|
||||||
|
if($fieldName) {
|
||||||
|
$dataObject->$fieldName = (float)preg_replace('/[^0-9.]/', '', $this->value);
|
||||||
|
} else {
|
||||||
|
user_error("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object", E_USER_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class CurrencyField extends TextField {
|
|||||||
*/
|
*/
|
||||||
function dataValue() {
|
function dataValue() {
|
||||||
if($this->value){
|
if($this->value){
|
||||||
return ereg_replace('[^0-9.]',"", $this->value);
|
return preg_replace('/[^0-9.]/',"", $this->value);
|
||||||
}else{
|
}else{
|
||||||
return 0.00;
|
return 0.00;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ class CurrencyField_Readonly extends ReadonlyField{
|
|||||||
function Field() {
|
function Field() {
|
||||||
if($this->value){
|
if($this->value){
|
||||||
$val = $this->dontEscape ? ($this->reserveNL?Convert::raw2xml($this->value):$this->value) : Convert::raw2xml($this->value);
|
$val = $this->dontEscape ? ($this->reserveNL?Convert::raw2xml($this->value):$this->value) : Convert::raw2xml($this->value);
|
||||||
$val = '$' . number_format(ereg_replace('[^0-9.]',"",$val), 2);
|
$val = '$' . number_format(preg_replace('/[^0-9.]/',"",$val), 2);
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
$val = '<i>$0.00</i>';
|
$val = '<i>$0.00</i>';
|
||||||
|
@ -538,7 +538,7 @@ class Form extends ViewableData {
|
|||||||
if($field->Name() == "ClassName"){
|
if($field->Name() == "ClassName"){
|
||||||
$lastField = $field;
|
$lastField = $field;
|
||||||
}else if( $dataObject->hasMethod( $saveMethod ) ){
|
}else if( $dataObject->hasMethod( $saveMethod ) ){
|
||||||
$dataObject->$saveMethod( $field->Value());
|
$dataObject->$saveMethod( $field->dataValue());
|
||||||
} else if($field->Name() != "ID"){
|
} else if($field->Name() != "ID"){
|
||||||
$field->saveInto($dataObject);
|
$field->saveInto($dataObject);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user