Ensure SelectFormField behave properly in some edge cases

This commit is contained in:
Ludovic Poujol 2019-03-27 11:09:02 +01:00
parent d3e5cc7b4c
commit 369415b5f5

View file

@ -879,7 +879,7 @@ class SelectFormField extends FormField {
} }
public function verify($set_error) { public function verify($set_error) {
if($this->mandatory && empty($this->value)) { if($this->mandatory && strlen($this->value) === 0) {
if($set_error) $this->error = 'Champ obligatoire'; if($set_error) $this->error = 'Champ obligatoire';
return FALSE; return FALSE;
} }
@ -894,7 +894,7 @@ class SelectFormField extends FormField {
$input .= ' <option value="">-- Choisissez --</option>'."\n"; $input .= ' <option value="">-- Choisissez --</option>'."\n";
foreach ($this->list as $value => $label) { foreach ($this->list as $value => $label) {
$input .= ' <option value="'.htmlspecialchars($value,ENT_QUOTES).'"'; $input .= ' <option value="'.htmlspecialchars($value,ENT_QUOTES).'"';
if ($this->value == $value) $input.=' selected="selected"'; if ($this->value == $value && strlen($this->value) !== 0) $input.=' selected="selected"';
$input .= '>'.$label.'</option>'."\n"; $input .= '>'.$label.'</option>'."\n";
} }
$input .= "</select>\n"; $input .= "</select>\n";