mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
f1c408d3f4
BUG Fixed display logic
45 lines
1.0 KiB
PHP
Executable File
45 lines
1.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* EditableRadioField
|
|
*
|
|
* Represents a set of selectable radio buttons
|
|
*
|
|
* @package userforms
|
|
*/
|
|
|
|
class EditableRadioField extends EditableMultipleOptionField {
|
|
|
|
private static $singular_name = 'Radio field';
|
|
|
|
private static $plural_name = 'Radio fields';
|
|
|
|
/**
|
|
* @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());
|
|
|
|
// Set default item
|
|
$defaultOption = $this->getDefaultOptions()->first();
|
|
if($defaultOption) {
|
|
$field->setValue($defaultOption->EscapedTitle);
|
|
}
|
|
$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}\")";
|
|
}
|
|
}
|