mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
9f112e3b23
Fix unit test failures
59 lines
1.3 KiB
PHP
Executable File
59 lines
1.3 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* EditableNumericField
|
|
*
|
|
* This control represents a user-defined numeric field in a user defined form
|
|
*
|
|
* @package userforms
|
|
*/
|
|
|
|
class EditableNumericField extends EditableFormField {
|
|
|
|
private static $singular_name = 'Numeric Field';
|
|
|
|
private static $plural_name = 'Numeric Fields';
|
|
|
|
private static $db = array(
|
|
'MinValue' => 'Int',
|
|
'MaxValue' => 'Int'
|
|
);
|
|
|
|
public function getSetsOwnError() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return NumericField
|
|
*/
|
|
public function getFormField() {
|
|
$field = new NumericField($this->Name, $this->EscapedTitle, $this->Default);
|
|
$field->addExtraClass('number');
|
|
$this->doUpdateFormField($field);
|
|
return $field;
|
|
}
|
|
|
|
public function getFieldValidationOptions() {
|
|
$fields = parent::getFieldValidationOptions();
|
|
$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)
|
|
)
|
|
));
|
|
return $fields;
|
|
}
|
|
|
|
public function getValidation() {
|
|
$options = array();
|
|
if($this->MinValue) {
|
|
$options['min'] = (int)$this->MinValue;
|
|
}
|
|
if($this->MaxValue) {
|
|
$options['max'] = (int)$this->MaxValue;
|
|
}
|
|
return $options;
|
|
}
|
|
}
|