From 05605a217d0adee02c1c3efd103935e9a8090383 Mon Sep 17 00:00:00 2001 From: John Rayes Date: Mon, 15 Mar 2021 03:15:31 -0700 Subject: [PATCH] fix: Make select boxes validate if no value provided and default is set --- src/Class-CustomForm.php | 2 +- tests/Test.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Class-CustomForm.php b/src/Class-CustomForm.php index 625665b..a549887 100644 --- a/src/Class-CustomForm.php +++ b/src/Class-CustomForm.php @@ -170,7 +170,7 @@ public function setHtml() } public function validate(): bool { - $found = isset(array_flip($this->type_vars)[$this->value]); + $found = isset(array_flip($this->type_vars)[$this->value]) || !empty($this->default); if (!$found && $this->required) $this->err = array('pf_invalid_value', $this->field['name']); diff --git a/tests/Test.php b/tests/Test.php index aeae80d..a634db4 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -78,7 +78,8 @@ public function selectProvider(): array { return [ ['gold,silver,bronze,default=silver', '', 'silver'], - ['gold,silver,bronze,default=', 'silver', 'silver'] + ['gold,silver,bronze,default=', 'silver', 'silver'], + ['gold,silver,bronze,default=silver', 'titanium', 'silver'] ]; }