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';
|
|
|
|
|
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() {
|
2014-07-24 11:37:11 +02:00
|
|
|
$field = new NumericField($this->Name, $this->Title);
|
|
|
|
$field->addExtraClass('number');
|
|
|
|
|
|
|
|
if ($field->Required) {
|
|
|
|
// Required and numeric validation can conflict so add the
|
|
|
|
// required validation messages as input attributes
|
|
|
|
$errorMessage = $this->getErrorMessage()->HTML();
|
|
|
|
|
|
|
|
$field->setAttribute('data-rule-required','true');
|
|
|
|
$field->setAttribute('data-msg-required',$errorMessage);
|
2014-02-10 00:40:20 +01:00
|
|
|
}
|
2014-07-24 11:37:11 +02:00
|
|
|
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValidationOptions() {
|
|
|
|
$fields = parent::getFieldValidationOptions();
|
|
|
|
|
|
|
|
$min = ($this->getSetting('MinValue')) ? $this->getSetting('MinValue') : '';
|
|
|
|
$max = ($this->getSetting('MaxValue')) ? $this->getSetting('MaxValue') : '';
|
|
|
|
|
|
|
|
$extraFields = new FieldList(
|
|
|
|
new NumericField($this->getSettingName('MinValue'), _t('EditableFormField.MINVALUE', 'Min Value'), $min),
|
|
|
|
new NumericField($this->getSettingName('MaxValue'), _t('EditableFormField.MAXVALUE', 'Max Value'), $max)
|
|
|
|
);
|
|
|
|
|
|
|
|
$fields->merge($extraFields);
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValidation() {
|
|
|
|
$options = array();
|
|
|
|
|
|
|
|
if($this->getSetting('MinValue')) {
|
|
|
|
$options['min'] = 0 + (int) $this->getSetting('MinValue');
|
2014-02-10 00:40:20 +01:00
|
|
|
}
|
2014-07-24 11:37:11 +02:00
|
|
|
|
|
|
|
if($this->getSetting('MaxValue')) {
|
|
|
|
$options['max'] = 0 + (int)$this->getSetting('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
|
|
|
}
|
|
|
|
}
|