| Total Complexity | 7 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class EditableRadioField extends EditableMultipleOptionField |
||
| 17 | { |
||
| 18 | private static $singular_name = 'Radio Group'; |
||
|
|
|||
| 19 | |||
| 20 | private static $plural_name = 'Radio Groups'; |
||
| 21 | |||
| 22 | private static $table_name = 'EditableRadioField'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return FieldList |
||
| 26 | */ |
||
| 27 | public function getCMSFields() |
||
| 28 | { |
||
| 29 | $fields = parent::getCMSFields(); |
||
| 30 | |||
| 31 | $fields->removeByName('Default'); |
||
| 32 | |||
| 33 | return $fields; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function getFormField() |
||
| 37 | { |
||
| 38 | $field = OptionsetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap()) |
||
| 39 | ->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder') |
||
| 40 | ->setTemplate('SilverStripe\\UserForms\\FormField\\UserFormsOptionSetField'); |
||
| 41 | |||
| 42 | // Set default item |
||
| 43 | $defaultOption = $this->getDefaultOptions()->first(); |
||
| 44 | if ($defaultOption) { |
||
| 45 | $field->setValue($defaultOption->Value); |
||
| 46 | } |
||
| 47 | $this->doUpdateFormField($field); |
||
| 48 | return $field; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) |
||
| 52 | { |
||
| 53 | // We only want to trigger on load once for the radio group - hence we focus on the first option only. |
||
| 54 | $first = $forOnLoad ? ':first' : ''; |
||
| 55 | return "$(\"input[name='{$this->Name}']{$first}\")"; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function isRadioField() |
||
| 61 | } |
||
| 62 | } |
||
| 63 |