1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EditableNumericField |
4
|
|
|
* |
5
|
|
|
* This control represents a user-defined numeric field in a user defined form |
6
|
|
|
* |
7
|
|
|
* @package userforms |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
class EditableNumericField extends EditableFormField |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
private static $singular_name = 'Numeric Field'; |
|
|
|
|
14
|
|
|
|
15
|
|
|
private static $plural_name = 'Numeric Fields'; |
|
|
|
|
16
|
|
|
|
17
|
|
|
private static $has_placeholder = true; |
|
|
|
|
18
|
|
|
|
19
|
|
|
private static $db = array( |
|
|
|
|
20
|
|
|
'MinValue' => 'Int', |
21
|
|
|
'MaxValue' => 'Int' |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
public function getSetsOwnError() |
25
|
|
|
{ |
26
|
|
|
return true; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return NumericField |
31
|
|
|
*/ |
32
|
|
|
public function getFormField() |
33
|
|
|
{ |
34
|
|
|
$field = NumericField::create($this->Name, $this->EscapedTitle, $this->Default) |
|
|
|
|
35
|
|
|
->setFieldHolderTemplate('UserFormsField_holder') |
36
|
|
|
->setTemplate('UserFormsField') |
37
|
|
|
->addExtraClass('number'); |
38
|
|
|
|
39
|
|
|
$this->doUpdateFormField($field); |
40
|
|
|
|
41
|
|
|
return $field; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getFieldValidationOptions() |
45
|
|
|
{ |
46
|
|
|
$fields = parent::getFieldValidationOptions(); |
47
|
|
|
$fields->push(FieldGroup::create( |
48
|
|
|
_t("EditableNumericField.RANGE", "Allowed numeric range"), |
49
|
|
|
array( |
50
|
|
|
new NumericField('MinValue', false), |
|
|
|
|
51
|
|
|
new LiteralField('RangeValue', _t("EditableNumericField.RANGE_TO", "to")), |
52
|
|
|
new NumericField('MaxValue', false) |
|
|
|
|
53
|
|
|
) |
54
|
|
|
)); |
55
|
|
|
return $fields; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Updates a formfield with the additional metadata specified by this field |
60
|
|
|
* |
61
|
|
|
* @param FormField $field |
62
|
|
|
*/ |
63
|
|
|
protected function updateFormField($field) |
64
|
|
|
{ |
65
|
|
|
parent::updateFormField($field); |
66
|
|
|
|
67
|
|
|
if ($this->MinValue) { |
|
|
|
|
68
|
|
|
$field->setAttribute('data-rule-min', $this->MinValue); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($this->MaxValue) { |
|
|
|
|
72
|
|
|
$field->setAttribute('data-rule-max', $this->MaxValue); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.