Skip to content

Commit

Permalink
fix(checkboxesfield,radiosfield,selectfield): add missing error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jun 14, 2023
1 parent acbcd09 commit 6658519
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,19 @@ public function isValidValue($value): bool {

foreach ($value as $item) {
if (trim($item) == '') {
Session::addMessageAfterRedirect(
sprintf(__('Empty values are not allowed: %s', 'formcreator'), $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}
if (!in_array($item, $this->getAvailableValues())) {
Session::addMessageAfterRedirect(
sprintf(__('This value %1$s is not alowed: %2$s', 'formcreator'), $item, $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}
}
Expand Down
12 changes: 11 additions & 1 deletion inc/field/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,18 @@ public function isValidValue($value): bool {
if ($value == '') {
return true;
}

$value = trim($value);
return in_array($value, $this->getAvailableValues());
if (!in_array($value, $this->getAvailableValues())) {
Session::addMessageAfterRedirect(
sprintf(__('This value %1$s is not allowed: %2$s', 'formcreator'), $value, $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}

return true;
}

public static function canRequire(): bool {
Expand Down
11 changes: 10 additions & 1 deletion inc/field/selectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ public function isValidValue($value): bool {
return true;
}
$value = trim($value);
return in_array($value, $this->getAvailableValues());
if (!in_array($value, $this->getAvailableValues())) {
Session::addMessageAfterRedirect(
sprintf(__('This value %1$s is not allowed: %2$s', 'formcreator'), $value, $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}

return true;
}

public function equals($value): bool {
Expand Down

0 comments on commit 6658519

Please sign in to comment.