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