silverstripe-framework/forms/NumericField.php
Sean Harvey 9f3344b355 API CHANGE Removed built-in behaviour.js client-side form validation.
This is no longer supported. Please use custom client-side validation instead. (see 3.0.0 changelog
for more information)
2012-03-09 12:19:57 +13:00

42 lines
847 B
PHP

<?php
/**
* A Single Numeric field extending a typical
* TextField but with validation.
* @package forms
* @subpackage fields-formattedinput
*/
class NumericField extends TextField{
function Field() {
$html = parent::Field();
Requirements::javascript(SAPPHIRE_DIR . 'javascript/NumericField.js');
return $html;
}
function Type() {
return 'numeric text';
}
/** PHP Validation **/
function validate($validator){
if($this->value && !is_numeric(trim($this->value))){
$validator->validationError(
$this->name,
sprintf(
_t('NumericField.VALIDATION', "'%s' is not a number, only numbers can be accepted for this field"),
$this->value
),
"validation"
);
return false;
} else{
return true;
}
}
function dataValue() {
return (is_numeric($this->value)) ? $this->value : 0;
}
}