/** * Count/length validator. * @param MultiSelectBox * @param array min and max length pair * @return bool */ public static function validateLength(MultiSelectBox $control, $range) { if (!is_array($range)) { $range = array($range, $range); } $count = count($control->getSelectedItem()); return ($range[0] === NULL || $count >= $range[0]) && ($range[1] === NULL || $count <= $range[1]); }
/** * Adds a validation rule. * @param mixed rule type * @param string message to display for invalid data * @param mixed optional rule arguments * @return FormControl provides a fluent interface */ public function addRule($operation, $message = NULL, $arg = NULL) { if ($operation === ':filled' and is_null($message)) { $message = 'Choose %label'; } return parent::addRule($operation, $message, $arg); }