Skip to content

Commit

Permalink
fix(fieldsfield): mandatory check failure on dropdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 23, 2024
1 parent 603b8ea commit 9ac92f0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion inc/field/fieldsfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public function isValidValue($value): bool {
public function isValid(): bool {
if (!is_null($this->getField())) {
// If the field is required it can't be empty
if ($this->getField()->fields['mandatory'] && $this->value == '') {
if ($this->isAdditionalFieldEmpty()) {
Session::addMessageAfterRedirect(
__('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(),
false,
Expand All @@ -498,6 +498,20 @@ public function isValid(): bool {
return true;
}

/**
* Undocumented function
*
* @return boolean
*/
private function isAdditionalFieldEmpty(): bool {
switch ($this->getField()->fields['type']) {
case 'dropdown':
return $this->getField()->fields['mandatory'] && $this->value == 0;
}

return $this->getField()->fields['mandatory'] && $this->value == '';
}

public function moveUploads() {

}
Expand Down

0 comments on commit 9ac92f0

Please sign in to comment.