Module: check_mk
Branch: master
Commit: 8627bb47231dc6ea66afdc7fc4a79fb3006696f3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8627bb47231dc6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri May 25 11:07:01 2012 +0200
Fixed another complain problem in CascadingDropdown
---
web/htdocs/valuespec.py | 40 +++++++++++++++++++++++++++-------------
1 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 2d90ff5..07cc648 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -789,8 +789,8 @@ class CascadingDropdown(ValueSpec):
ValueSpec.__init__(self, **kwargs)
self._choices = []
for entry in kwargs["choices"]:
- if len(entry) == 2:
- entry = entry + (None,)
+ if len(entry) == 2: # plain entry with no sub-valuespec
+ entry = entry + (None,) # normlize to three entries
self._choices.append(entry)
self._separator = kwargs.get("separator", ", ")
self._html_separator = kwargs.get("html_separator",
"<br>")
@@ -803,10 +803,15 @@ class CascadingDropdown(ValueSpec):
return self._choices[0][0]
def render_input(self, varprefix, value):
- def_val = 0
+ def_val = '0'
options = []
for nr, (val, title, vs) in enumerate(self._choices):
options.append((str(nr), title))
+ # Determine the default value for the select, so the
+ # the dropdown pre-selects the line corresponding with value.
+ # Note: the html.select with automatically show the modified
+ # selection, if the HTML variable varprefix_sel aleady
+ # exists.
if value == val or (
type(value) == tuple and value[0] == val):
def_val = str(nr)
@@ -818,22 +823,31 @@ class CascadingDropdown(ValueSpec):
else:
html.sorted_select(vp, options, def_val, onchange=onchange)
+ # make sure, that the visibility is done correctly, in both
+ # cases:
+ # 1. Form painted for the first time (no submission yet, vp missing in URL
+ # 2. Form already submitted -> honor URL variable vp for visibility
cur_val = html.var(vp)
html.write(self._html_separator)
for nr, (val, title, vs) in enumerate(self._choices):
if vs:
vp = varprefix + "_%d" % nr
- if value == val \
- or (type(value) == tuple and value[0] == val):
- def_val_2 = value[1]
- disp = ""
- elif cur_val == str(nr):
- def_val_2 = vs.default_value()
- disp = ""
- else:
- def_val_2 = vs.default_value()
- disp = "none"
+ # Form already submitted once (and probably in complain state)
+ if cur_val != None:
+ def_val_2 = vs.default_value() # not used anyway, form already
submitted
+ if cur_val == str(nr):
+ disp = ""
+ else:
+ disp = "none"
+ else: # form painted the first time
+ if value == val \
+ or (type(value) == tuple and value[0] == val):
+ def_val_2 = value[1]
+ disp = ""
+ else:
+ def_val_2 = vs.default_value()
+ disp = "none"
html.write('<span id="%s_%s_sub" style="display:
%s">' % (varprefix, nr, disp))
vs.render_input(vp, def_val_2)
html.write('</span>')