Module: check_mk
Branch: master
Commit: fd933a5e733638eb20a475372d3b0e9bdee69304
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fd933a5e733638…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon May 30 12:14:52 2011 +0200
Multisite: fix default value of checkboxes
---
web/htdocs/htmllib.py | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 662f981..ae6ae74 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -215,6 +215,11 @@ class html:
if value != None:
self.write("<input type=hidden name=%s
value=\"%s\">\n" % (var, attrencode(value)))
+ # Beware: call this method just before end_form(). It will
+ # add all current non-underscored HTML variables as hiddedn
+ # field to the form - *if* they are not used in any input
+ # field. (this is the reason why you must not add any further
+ # input fields after this method has been called).
def hidden_fields(self, varlist = None, **args):
add_action_vars = args.get("add_action_vars", False)
if varlist != None:
@@ -325,7 +330,16 @@ class html:
error = self.user_errors.get(varname)
if error:
html = "<x class=inputerror>"
- value = self.req.vars.get(varname, deflt)
+ # Problem with checkboxes: The browser will add the variable
+ # only to the URL if the box is checked. So in order to detect
+ # wether we should add the default value, we need to detect
+ # if the form is printed for the first time. This is the
+ # case if "filled_in" is not set.
+ if not self.has_var("filled_in"):
+ value = self.req.vars.get(varname, deflt)
+ else:
+ value = self.req.vars.get(varname, "")
+
if value != "" and value != False:
checked = " CHECKED"
else: