Skip to content

Commit

Permalink
Merge pull request #332 from skeeks-semenov/master
Browse files Browse the repository at this point in the history
Enhance Select2 required attribute validation when used with model
  • Loading branch information
kartik-v authored Dec 15, 2020
2 parents dbfe450 + e5d3364 commit 05ed365
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,14 @@ protected function isRequired()
$validators = $this->model->getActiveValidators($this->attribute);
foreach ($validators as $validator) {
if ($validator instanceof RequiredValidator) {
return true;
if (is_callable($validator->when)) {
if (call_user_func($validator->when, $this->model, $this->attribute)) {
return true;
}
} else {
return true;
}

}
}
return false;
Expand Down

0 comments on commit 05ed365

Please sign in to comment.