2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 04:26:40 +02:00
|
|
|
* EditableCheckboxGroup
|
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* Represents a set of selectable radio buttons
|
2015-09-11 00:20:06 +02:00
|
|
|
*
|
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 EditableCheckboxGroupField extends EditableMultipleOptionField
|
|
|
|
{
|
|
|
|
|
|
|
|
private static $singular_name = "Checkbox Group";
|
|
|
|
|
|
|
|
private static $plural_name = "Checkbox Groups";
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
|
|
|
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
|
|
|
|
|
|
|
// Set the default checked items
|
|
|
|
$defaultCheckedItems = $this->getDefaultOptions();
|
|
|
|
if ($defaultCheckedItems->count()) {
|
|
|
|
$field->setDefaultItems($defaultCheckedItems->map('EscapedTitle')->keys());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->doUpdateFormField($field);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValueFromData($data)
|
|
|
|
{
|
|
|
|
$result = '';
|
|
|
|
$entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
|
|
|
|
|
|
|
if ($entries) {
|
|
|
|
if (!is_array($data[$this->Name])) {
|
|
|
|
$entries = array($data[$this->Name]);
|
|
|
|
}
|
|
|
|
foreach ($entries as $selected => $value) {
|
|
|
|
if (!$result) {
|
|
|
|
$result = $value;
|
|
|
|
} else {
|
|
|
|
$result .= ", " . $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
|
|
|
{
|
|
|
|
// watch out for checkboxs as the inputs don't have values but are 'checked
|
|
|
|
// @todo - Test this
|
|
|
|
if ($rule->FieldValue) {
|
|
|
|
return "$(\"input[name='{$this->Name}[]'][value='{$rule->FieldValue}']\")";
|
|
|
|
} else {
|
|
|
|
return "$(\"input[name='{$this->Name}[]']:first\")";
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 09:08:21 +02:00
|
|
|
}
|