2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 02:26:40 +00:00
|
|
|
* EditableCheckboxGroup
|
|
|
|
*
|
2008-09-29 03:18:23 +00:00
|
|
|
* Represents a set of selectable radio buttons
|
2015-09-11 10:20:06 +12:00
|
|
|
*
|
2009-04-17 02:26:40 +00:00
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2009-04-17 02:26:40 +00:00
|
|
|
class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
2008-09-29 03:18:23 +00:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $singular_name = "Checkbox Group";
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $plural_name = "Checkbox Groups";
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFormField() {
|
2015-08-10 17:03:36 +12:00
|
|
|
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
2015-08-21 09:51:19 +12:00
|
|
|
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
2013-05-08 10:08:21 +03:00
|
|
|
|
2015-07-24 14:37:48 +12:00
|
|
|
// Set the default checked items
|
2015-08-10 17:03:36 +12:00
|
|
|
$defaultCheckedItems = $this->getDefaultOptions();
|
2015-07-24 14:37:48 +12:00
|
|
|
if ($defaultCheckedItems->count()) {
|
|
|
|
$field->setDefaultItems($defaultCheckedItems->map('EscapedTitle')->keys());
|
|
|
|
}
|
|
|
|
|
2015-08-10 17:03:36 +12:00
|
|
|
$this->doUpdateFormField($field);
|
2015-07-24 14:37:48 +12:00
|
|
|
return $field;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getValueFromData($data) {
|
2009-01-28 05:59:23 +00:00
|
|
|
$result = '';
|
2009-04-28 02:03:13 +00:00
|
|
|
$entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2009-04-27 06:00:05 +00:00
|
|
|
if($entries) {
|
2009-04-28 02:03:13 +00:00
|
|
|
if(!is_array($data[$this->Name])) {
|
|
|
|
$entries = array($data[$this->Name]);
|
|
|
|
}
|
2009-04-27 06:00:05 +00:00
|
|
|
foreach($entries as $selected => $value) {
|
|
|
|
if(!$result) {
|
|
|
|
$result = $value;
|
|
|
|
} else {
|
|
|
|
$result .= ", " . $value;
|
|
|
|
}
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2015-08-13 11:31:37 +12:00
|
|
|
|
|
|
|
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 10:08:21 +03:00
|
|
|
}
|