Skip to content

Commit

Permalink
Merge pull request #42 from r-st/signal-type-check
Browse files Browse the repository at this point in the history
Add type checks to multi choice signal procesing
  • Loading branch information
duskohu authored Aug 20, 2021
2 parents 4bbac6b + d549e3c commit 47ac676
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Controls/DependentMultiSelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ public function signalReceived(string $signal) : void
$value = $presenter->getParameter($this->getNormalizeName($parent));

if ($parent instanceof Nette\Forms\Controls\MultiChoiceControl) {
$value = explode(',', $value);
$value = array_filter($value, static function ($val) {return !in_array($val, [null, '', []], true);});
if (is_string($value)) {
$value = explode(',', $value);
}
if ($value !== null) {
$value = array_filter($value, static function ($val) {return !in_array($val, [null, '', []], true);});
}
}

$parent->setValue($value);
Expand Down
9 changes: 7 additions & 2 deletions src/Controls/DependentSelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public function signalReceived(string $signal) : void
$value = $presenter->getParameter($this->getNormalizeName($parent));

if ($parent instanceof Nette\Forms\Controls\MultiChoiceControl) {
$value = explode(',', $value);
$value = array_filter($value, static function ($val) {return !in_array($val, [null, '', []], true);});
if (is_string($value)) {
$value = explode(',', $value);
}

if ($value !== null) {
$value = array_filter($value, static function ($val) {return !in_array($val, [null, '', []], true);});
}
}

$parent->setValue($value);
Expand Down

0 comments on commit 47ac676

Please sign in to comment.