Skip to content

Commit cb380f9

Browse files
committed
fix(fieldsfield): mandatory check failure on dropdowns
1 parent 11d9e6b commit cb380f9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

inc/field/fieldsfield.class.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public function isValidValue($value): bool {
483483
public function isValid(): bool {
484484
if (!is_null($this->getField())) {
485485
// If the field is required it can't be empty
486-
if ($this->getField()->fields['mandatory'] && $this->value == '') {
486+
if ($this->isAdditionalFieldEmpty()) {
487487
Session::addMessageAfterRedirect(
488488
__('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(),
489489
false,
@@ -498,6 +498,20 @@ public function isValid(): bool {
498498
return true;
499499
}
500500

501+
/**
502+
* Undocumented function
503+
*
504+
* @return boolean
505+
*/
506+
private function isAdditionalFieldEmpty(): bool {
507+
switch ($this->getField()->fields['type']) {
508+
case 'dropdown':
509+
return $this->getField()->fields['mandatory'] && $this->value == 0;
510+
}
511+
512+
return $this->getField()->fields['mandatory'] && $this->value == '';
513+
}
514+
501515
public function moveUploads() {
502516

503517
}

0 commit comments

Comments
 (0)