2014-07-25 04:52:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
class UserFormsCheckboxSetField extends CheckboxSetField {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery validate requires that the value of the option does not contain
|
|
|
|
* the actual value of the input.
|
|
|
|
*
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
|
|
|
public function getOptions() {
|
|
|
|
$options = parent::getOptions();
|
|
|
|
|
|
|
|
foreach($options as $option) {
|
|
|
|
$option->Name = "{$this->name}[]";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2016-05-15 22:25:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getSourceAsArray()
|
|
|
|
{
|
|
|
|
$array = parent::getSourceAsArray();
|
|
|
|
|
|
|
|
return array_values($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* @param Validator $validator
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function validate($validator)
|
|
|
|
{
|
|
|
|
// get the previous values (could contain comma-delimited list)
|
|
|
|
|
|
|
|
$previous = $value = $this->Value();
|
|
|
|
|
2016-06-19 23:54:33 +02:00
|
|
|
if (is_string($value) && strstr($value, ",")) {
|
2016-05-15 22:25:09 +02:00
|
|
|
$value = explode(",", $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the value as an array for parent validation
|
|
|
|
|
|
|
|
$this->setValue($value);
|
|
|
|
|
|
|
|
$validated = parent::validate($validator);
|
|
|
|
|
|
|
|
// restore previous value after validation
|
|
|
|
|
|
|
|
$this->setValue($previous);
|
|
|
|
|
|
|
|
return $validated;
|
|
|
|
}
|
|
|
|
}
|