2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 02:26:40 +00:00
|
|
|
* EditableRadioField
|
|
|
|
*
|
2008-09-29 03:18:23 +00:00
|
|
|
* Represents a set of selectable radio buttons
|
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 EditableRadioField extends EditableMultipleOptionField {
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2015-08-17 14:05:50 +12:00
|
|
|
private static $singular_name = 'Radio Group';
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2015-08-17 14:05:50 +12:00
|
|
|
private static $plural_name = 'Radio Groups';
|
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
|
|
|
|
2012-07-17 16:09:31 +12:00
|
|
|
public function getFormField() {
|
2015-08-10 17:03:36 +12:00
|
|
|
$field = OptionsetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
2015-08-21 09:51:19 +12:00
|
|
|
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
2015-07-24 14:37:48 +12:00
|
|
|
|
2015-08-10 17:03:36 +12:00
|
|
|
// Set default item
|
|
|
|
$defaultOption = $this->getDefaultOptions()->first();
|
|
|
|
if($defaultOption) {
|
|
|
|
$field->setValue($defaultOption->EscapedTitle);
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2015-08-10 17:03:36 +12:00
|
|
|
$this->doUpdateFormField($field);
|
2015-07-24 14:37:48 +12:00
|
|
|
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) {
|
|
|
|
// We only want to trigger on load once for the radio group - hence we focus on the first option only.
|
|
|
|
$first = $forOnLoad ? ':first' : '';
|
|
|
|
return "$(\"input[name='{$this->Name}']{$first}\")";
|
|
|
|
}
|
2012-07-17 16:09:31 +12:00
|
|
|
}
|