2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableDropdown
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
2010-09-03 05:06:13 +00:00
|
|
|
* Represents a modifiable dropdown (select) box on a form
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2009-04-17 02:26:40 +00:00
|
|
|
class EditableDropdown extends EditableMultipleOptionField {
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $singular_name = 'Dropdown Field';
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $plural_name = 'Dropdowns';
|
2015-07-24 14:37:48 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
|
|
|
$fields->removeByName('Default');
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2010-09-03 05:06:13 +00:00
|
|
|
/**
|
|
|
|
* @return DropdownField
|
|
|
|
*/
|
2015-07-24 14:37:48 +12:00
|
|
|
public function getFormField() {
|
2015-08-21 15:21:33 +12:00
|
|
|
$field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap())
|
|
|
|
->setFieldHolderTemplate('UserFormsField_holder')
|
|
|
|
->setTemplate('UserFormsDropdownField');
|
2010-09-03 05:06:13 +00:00
|
|
|
|
2015-08-10 17:03:36 +12:00
|
|
|
// Set default
|
|
|
|
$defaultOption = $this->getDefaultOptions()->first();
|
|
|
|
if($defaultOption) {
|
|
|
|
$field->setValue($defaultOption->EscapedTitle);
|
2009-04-17 02:26:40 +00:00
|
|
|
}
|
2015-08-10 17:03:36 +12:00
|
|
|
$this->doUpdateFormField($field);
|
2014-12-22 12:19:33 +10:30
|
|
|
return $field;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2015-08-13 11:31:37 +12:00
|
|
|
|
|
|
|
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
|
|
|
return "$(\"select[name='{$this->Name}']\")";
|
|
|
|
}
|
2009-12-07 02:04:20 +00:00
|
|
|
}
|