Skip to content

Commit

Permalink
fix: Make select boxes validate if no value provided and default is set
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Mar 16, 2021
1 parent 4abc062 commit 05605a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Class-CustomForm.php
Expand Up @@ -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']);
Expand Down
3 changes: 2 additions & 1 deletion tests/Test.php
Expand Up @@ -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']
];
}

Expand Down

0 comments on commit 05605a2

Please sign in to comment.