silverstripe-userforms/code/Model/EditableFormField/EditableRadioField.php

63 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\UserForms\Model\EditableCustomRule;
/**
* EditableRadioField
*
* Represents a set of selectable radio buttons
*
* @package userforms
*/
2016-07-21 07:53:59 +02:00
class EditableRadioField extends EditableMultipleOptionField
{
private static $singular_name = 'Radio Group';
private static $plural_name = 'Radio Groups';
private static $table_name = 'EditableRadioField';
2016-07-21 07:53:59 +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())
->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
->setTemplate('UserFormsOptionSetField'); // @todo
2016-07-21 07:53:59 +02:00
// Set default item
$defaultOption = $this->getDefaultOptions()->first();
if ($defaultOption) {
2017-06-13 01:49:02 +02:00
$field->setValue($defaultOption->Value);
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}\")";
}
2017-08-11 02:37:03 +02:00
public function isRadioField()
{
return true;
}
}