Skip to content

Commit 05ed365

Browse files
authored
Merge pull request #332 from skeeks-semenov/master
Enhance Select2 required attribute validation when used with model
2 parents dbfe450 + e5d3364 commit 05ed365

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Select2.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,14 @@ protected function isRequired()
459459
$validators = $this->model->getActiveValidators($this->attribute);
460460
foreach ($validators as $validator) {
461461
if ($validator instanceof RequiredValidator) {
462-
return true;
462+
if (is_callable($validator->when)) {
463+
if (call_user_func($validator->when, $this->model, $this->attribute)) {
464+
return true;
465+
}
466+
} else {
467+
return true;
468+
}
469+
463470
}
464471
}
465472
return false;

0 commit comments

Comments
 (0)