From 9ac92f04705060106b122d6665a3bb27f4adc4f0 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 23 Apr 2024 11:04:59 +0200 Subject: [PATCH] fix(fieldsfield): mandatory check failure on dropdowns --- inc/field/fieldsfield.class.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/inc/field/fieldsfield.class.php b/inc/field/fieldsfield.class.php index 7c6c282eb..dd3d2ed35 100644 --- a/inc/field/fieldsfield.class.php +++ b/inc/field/fieldsfield.class.php @@ -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, @@ -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() { }