2014-02-10 00:40:20 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableNumericField
|
|
|
|
*
|
|
|
|
* This control represents a user-defined numeric field in a user defined form
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
|
2014-07-24 11:37:11 +02:00
|
|
|
class EditableNumericField extends EditableFormField {
|
2014-02-10 00:40:20 +01:00
|
|
|
|
|
|
|
private static $singular_name = 'Numeric Field';
|
|
|
|
|
|
|
|
private static $plural_name = 'Numeric Fields';
|
2015-07-24 04:37:48 +02:00
|
|
|
|
|
|
|
private static $db = array(
|
|
|
|
'MinValue' => 'Int',
|
|
|
|
'MaxValue' => 'Int'
|
|
|
|
);
|
2014-02-10 00:40:20 +01:00
|
|
|
|
2014-04-16 01:48:10 +02:00
|
|
|
public function getSetsOwnError() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-10 00:40:20 +01:00
|
|
|
/**
|
2014-07-24 11:37:11 +02:00
|
|
|
* @return NumericField
|
2014-02-10 00:40:20 +01:00
|
|
|
*/
|
|
|
|
public function getFormField() {
|
2015-08-10 07:03:36 +02:00
|
|
|
$field = new NumericField($this->Name, $this->EscapedTitle, $this->Default);
|
2014-07-24 11:37:11 +02:00
|
|
|
$field->addExtraClass('number');
|
2015-08-10 07:03:36 +02:00
|
|
|
$this->doUpdateFormField($field);
|
2014-07-24 11:37:11 +02:00
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValidationOptions() {
|
|
|
|
$fields = parent::getFieldValidationOptions();
|
2015-07-24 04:37:48 +02:00
|
|
|
$fields->push(FieldGroup::create(
|
|
|
|
_t("EditableNumericField.RANGE", "Allowed numeric range"),
|
|
|
|
array(
|
|
|
|
new NumericField('MinValue', false),
|
|
|
|
new LiteralField('RangeValue', _t("EditableNumericField.RANGE_TO", "to")),
|
|
|
|
new NumericField('MaxValue', false)
|
|
|
|
)
|
|
|
|
));
|
2014-07-24 11:37:11 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValidation() {
|
|
|
|
$options = array();
|
2015-07-24 04:37:48 +02:00
|
|
|
if($this->MinValue) {
|
|
|
|
$options['min'] = (int)$this->MinValue;
|
2014-02-10 00:40:20 +01:00
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
if($this->MaxValue) {
|
|
|
|
$options['max'] = (int)$this->MaxValue;
|
2014-02-12 00:14:42 +01:00
|
|
|
}
|
2014-07-24 11:37:11 +02:00
|
|
|
return $options;
|
2014-02-10 00:40:20 +01:00
|
|
|
}
|
|
|
|
}
|