1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
<?php
namespace MvcCore\Ext\Form\Validators;
require_once(__DIR__.'/../../Form.php');
require_once(__DIR__.'/../Core/Field.php');
require_once('ValueInOptions.php');
use
MvcCore\Ext\Form,
MvcCore\Ext\Form\Core;
class MaxSelectedOptions extends ValueInOptions
{
public function Validate ($submitValue, $fieldName, \MvcCore\Ext\Form\Core\Field & $field) {
$safeValue = is_array($submitValue) ? $submitValue : array();
$safeValueCount = count($safeValue);
if ($field->MaxSelectedOptionsCount > 0 && $safeValueCount > $field->MaxSelectedOptionsCount) {
$this->addError(
$field,
Form::$DefaultMessages[Form::CHOOSE_MAX_OPTS],
function ($msg, $args) use (& $field) {
$args[] = $field->MaxSelectedOptionsCount;
return Core\View::Format($msg, $args);
}
);
}
return $safeValue;
}
}