summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshubhamdang <shubham@voereir.com>2021-05-19 20:36:24 +0530
committerShubham Dang <shubham@voereir.com>2021-05-19 15:11:21 +0000
commitcb8ff870904e775f30ae55c47f5ce8bf9027b1ed (patch)
tree26aa8adec1afc6b341ce1faa426e6372297db5f2
parent6071b622b26083ba996e7e6ccbbaced27b4356af (diff)
downloadhorizon-cb8ff870904e775f30ae55c47f5ce8bf9027b1ed.tar.gz
Added a condition to check whether value is in present in choices for ThemableSelectWidget.
Sometimes value is populated with uuid of resources but that resource is not present in openstack, So it is good to change initial_value with one of the values from choices. Closes-Bug: #1928953 Change-Id: Ia33aaf7019d73f96c27e75ee24d80dcbf3e8ceb2
-rw-r--r--horizon/forms/fields.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/horizon/forms/fields.py b/horizon/forms/fields.py
index 99c99c9bf..f2db9fce3 100644
--- a/horizon/forms/fields.py
+++ b/horizon/forms/fields.py
@@ -308,6 +308,8 @@ class ThemableSelectWidget(SelectWidget):
new_choices = []
initial_value = value
+ # Initially assuming value is not present in choices.
+ value_in_choices = False
for opt_value, opt_label in itertools.chain(self.choices, choices):
other_html = self.transform_option_html_attrs(opt_label)
@@ -318,15 +320,19 @@ class ThemableSelectWidget(SelectWidget):
opt_label = self.transform_option_label(opt_label)
# If value exists, save off its label for use
+ # and setting value in choices to True
if opt_value == value:
initial_value = opt_label
+ value_in_choices = True
if other_html:
new_choices.append((opt_value, opt_label, other_html))
else:
new_choices.append((opt_value, opt_label))
- if value is None and new_choices:
+ # if value is None or it is not present in choices then set
+ # the first value of choices.
+ if (value is None or not value_in_choices) and new_choices:
initial_value = new_choices[0][1]
attrs = self.build_attrs(attrs)