Hi,
in germany it is usual to enter the comma as decimal separator.
When using db fields as type 'Float', the "NumericField" is used by scaffolded forms.
Here you get a validation error when typing "9,99" because "9.99" is expected.
I built a custom numeric field as 'AWNumericField':
class AWNumericField extends TextField{
function Field() {
$html = parent::Field();
//Requirements::javascript(SAPPHIRE_DIR . 'javascript/NumericField.js');
return $html;
}
/** PHP Validation **/
function validate($validator){
$this->value = str_replace(',', '.', $this->value);
if($this->value && !is_numeric(trim($this->value))){
$validator->validationError(
$this->name,
sprintf(
_t('AWNumericField.VALIDATION', "'%s' is not a number, only numbers can be accepted for this field"),
$this->value
),
"validation"
);
return false;
} else{
return true;
}
}
function Value() {
return number_format($this->value, 2, ',', '.');
}
}
And it works when i build forms using this field.
But i want sapphire to take this field by default (by scaffolding)
I thougt that
Object::useCustomClass('NumericField', 'AWNumericField');
//or
Object::useCustomClass('NumericField', 'AWNumericField', true);
would do the job.
It does not.
Now i tried to build an extension an override some methods:
class NumericFieldExtension extends Extension {
function Field() {
$html = parent::Field();
//Requirements::javascript(SAPPHIRE_DIR . 'javascript/NumericField.js');
return $html;
}
function jsValidation() {
return;
}
/** PHP Validation **/
function validate($validator){
$this->value = str_replace(',', '.', $this->value);
if($this->value && !is_numeric(trim($this->value))){
$validator->validationError(
$this->name,
sprintf(
_t('AWNumericField.VALIDATION', "'%s' is not a number, only numbers can be accepted for this field"),
$this->value
),
"validation"
);
return false;
} else{
return true;
}
}
function Value() {
return number_format($this->value, 2, ',', '.');
}
}
and in _config.php
Object::add_extension('NumericField', 'NumericFieldExtension');
Still doesn't work .....
Any ideas or suggestions ?
Rob