2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 04:26:40 +02:00
|
|
|
* EditableRadioField
|
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* Represents a set of selectable radio buttons
|
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 EditableRadioField extends EditableMultipleOptionField
|
|
|
|
{
|
|
|
|
|
|
|
|
private static $singular_name = 'Radio Group';
|
|
|
|
|
|
|
|
private static $plural_name = 'Radio Groups';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
|
|
|
$fields->removeByName('Default');
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
$field = OptionsetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
|
|
|
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
|
|
|
|
|
|
|
// Set default item
|
|
|
|
$defaultOption = $this->getDefaultOptions()->first();
|
|
|
|
if ($defaultOption) {
|
2017-06-08 13:01:55 +02:00
|
|
|
$field->setValue($defaultOption->EscapedValue);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
$this->doUpdateFormField($field);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 06:09:31 +02:00
|
|
|
}
|