silverstripe-userforms/code/model/editableformfields/EditableRadioField.php

46 lines
1.1 KiB
PHP
Raw Normal View History

<?php
/**
* EditableRadioField
*
* Represents a set of selectable radio buttons
*
* @package userforms
*/
class EditableRadioField extends EditableMultipleOptionField {
2015-08-17 04:05:50 +02:00
private static $singular_name = 'Radio Group';
2015-08-17 04:05:50 +02:00
private static $plural_name = 'Radio Groups';
2015-07-24 04:37:48 +02:00
/**
* @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');
2015-07-24 04:37:48 +02:00
// Set default item
$defaultOption = $this->getDefaultOptions()->first();
if($defaultOption) {
$field->setValue($defaultOption->EscapedTitle);
}
$this->doUpdateFormField($field);
2015-07-24 04:37:48 +02:00
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}\")";
}
}