2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-06-26 15:03:11 +02:00
|
|
|
* Text input field with validation for numeric values.
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-formattedinput
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class NumericField extends TextField{
|
2011-12-22 13:10:57 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Type() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return 'numeric text';
|
|
|
|
}
|
2012-04-11 05:55:07 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/** PHP Validation **/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function validate($validator){
|
2009-04-29 01:55:53 +02:00
|
|
|
if($this->value && !is_numeric(trim($this->value))){
|
2007-10-25 04:47:45 +02:00
|
|
|
$validator->validationError(
|
|
|
|
$this->name,
|
2012-05-01 21:44:54 +02:00
|
|
|
_t(
|
|
|
|
'NumericField.VALIDATION', "'{value}' is not a number, only numbers can be accepted for this field",
|
|
|
|
array('value' => $this->value)
|
2007-10-25 04:47:45 +02:00
|
|
|
),
|
|
|
|
"validation"
|
|
|
|
);
|
2007-07-19 12:40:28 +02:00
|
|
|
return false;
|
|
|
|
} else{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function dataValue() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return (is_numeric($this->value)) ? $this->value : 0;
|
|
|
|
}
|
|
|
|
}
|