2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
2017-08-09 01:55:09 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\OptionsetField;
|
|
|
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
/**
|
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';
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
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()
|
|
|
|
{
|
2018-03-23 04:23:51 +01:00
|
|
|
$field = OptionsetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
|
2017-08-14 02:29:57 +02:00
|
|
|
->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
|
2017-08-22 01:30:37 +02:00
|
|
|
->setTemplate('SilverStripe\\UserForms\\FormField\\UserFormsOptionSetField');
|
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-04-28 00:22:15 +02:00
|
|
|
|
2017-08-11 02:37:03 +02:00
|
|
|
public function isRadioField()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-17 06:09:31 +02:00
|
|
|
}
|