2014-07-25 04:52:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package userforms
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class UserFormsCheckboxSetField extends CheckboxSetField
|
|
|
|
{
|
2014-07-25 04:52:56 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* 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();
|
2014-07-25 04:52:56 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
foreach ($options as $option) {
|
|
|
|
$option->Name = "{$this->name}[]";
|
|
|
|
}
|
2014-07-25 04:52:56 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return $options;
|
|
|
|
}
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getSourceAsArray()
|
|
|
|
{
|
|
|
|
$array = parent::getSourceAsArray();
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return array_values($array);
|
|
|
|
}
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* @param Validator $validator
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function validate($validator)
|
|
|
|
{
|
|
|
|
// get the previous values (could contain comma-delimited list)
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$previous = $value = $this->Value();
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
if (is_string($value) && strstr($value, ",")) {
|
|
|
|
$value = explode(",", $value);
|
|
|
|
}
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
// set the value as an array for parent validation
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$this->setValue($value);
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$validated = parent::validate($validator);
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
// restore previous value after validation
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$this->setValue($previous);
|
2016-05-15 22:25:09 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return $validated;
|
|
|
|
}
|
2016-05-15 22:25:09 +02:00
|
|
|
}
|