1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* EditableDropdown |
5
|
|
|
* |
6
|
|
|
* Represents a modifiable dropdown (select) box on a form |
7
|
|
|
* |
8
|
|
|
* @property bool $UseEmptyString |
9
|
|
|
* @property string $EmptyString |
10
|
|
|
* |
11
|
|
|
* @package userforms |
12
|
|
|
*/ |
13
|
|
|
class EditableDropdown extends EditableMultipleOptionField |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
private static $singular_name = 'Dropdown Field'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
private static $plural_name = 'Dropdowns'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
private static $db = array( |
|
|
|
|
21
|
|
|
'UseEmptyString' => 'Boolean', |
22
|
|
|
'EmptyString' => 'Varchar(255)', |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return FieldList |
27
|
|
|
*/ |
28
|
|
|
public function getCMSFields() |
29
|
|
|
{ |
30
|
|
|
$fields = parent::getCMSFields(); |
31
|
|
|
|
32
|
|
|
$fields->addFieldToTab( |
33
|
|
|
'Root.Main', |
34
|
|
|
CheckboxField::create('UseEmptyString') |
35
|
|
|
->setTitle('Set default empty string') |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$fields->addFieldToTab( |
39
|
|
|
'Root.Main', |
40
|
|
|
TextField::create('EmptyString') |
41
|
|
|
->setTitle('Empty String') |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$fields->removeByName('Default'); |
45
|
|
|
|
46
|
|
|
return $fields; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return DropdownField |
51
|
|
|
*/ |
52
|
2 |
|
public function getFormField() |
53
|
|
|
{ |
54
|
2 |
|
$field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap()) |
|
|
|
|
55
|
2 |
|
->setFieldHolderTemplate('UserFormsField_holder') |
56
|
2 |
|
->setTemplate('UserFormsDropdownField'); |
57
|
|
|
|
58
|
2 |
|
if ($this->UseEmptyString) { |
59
|
1 |
|
$field->setEmptyString(($this->EmptyString) ? $this->EmptyString : ''); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
// Set default |
63
|
2 |
|
$defaultOption = $this->getDefaultOptions()->first(); |
64
|
2 |
|
if ($defaultOption) { |
65
|
|
|
$field->setValue($defaultOption->Value); |
66
|
|
|
} |
67
|
2 |
|
$this->doUpdateFormField($field); |
68
|
2 |
|
return $field; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) |
72
|
|
|
{ |
73
|
|
|
return "$(\"select[name='{$this->Name}']\")"; |
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.