Unverified Commit fb58fb5f authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(SelectAttribute) Make sure postValue contains a valid choice...

:ambulance: fix(SelectAttribute) Make sure postValue contains a valid choice after a call to setChoices

issue #6138
Showing with 10 additions and 2 deletions
+10 -2
...@@ -76,8 +76,12 @@ class SelectAttribute extends Attribute ...@@ -76,8 +76,12 @@ class SelectAttribute extends Attribute
} }
} }
$this->choices = $choices; $this->choices = $choices;
if (!in_array($this->defaultValue, $this->choices, TRUE) && isset($this->choices[0])) { if (!in_array($this->defaultValue, $this->choices, TRUE)) {
$this->defaultValue = $this->choices[0]; if (isset($this->choices[0])) {
$this->defaultValue = $this->choices[0];
} else {
$this->defaultValue = '';
}
} }
if (is_array($outputs)) { if (is_array($outputs)) {
$this->setDisplayChoices($outputs); $this->setDisplayChoices($outputs);
...@@ -85,6 +89,10 @@ class SelectAttribute extends Attribute ...@@ -85,6 +89,10 @@ class SelectAttribute extends Attribute
if (!in_array($this->value, $this->choices)) { if (!in_array($this->value, $this->choices)) {
$this->resetToDefault(); $this->resetToDefault();
} }
if (!in_array($this->postValue, $this->choices)) {
/* We may be called between readPostValue and applyPostValue */
$this->postValue = $this->defaultValue;
}
} }
/*! \brief Set the display options of the select attribute /*! \brief Set the display options of the select attribute
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment