Module: check_mk
Branch: master
Commit: ddf0bd695023ad7d7d11b457417cb4425d6cf7de
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ddf0bd695023ad…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 14 09:59:56 2017 +0200
DropdownChoice() valuespec can now be read only
Change-Id: Iea31e388ce52c6db424b7b241d429d4e402b1a90
---
web/htdocs/htmllib.py | 4 ++++
web/htdocs/valuespec.py | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 34483cb..721b528 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -2404,6 +2404,10 @@ class html(HTMLGenerator, RequestHandler):
if error:
self.open_x(class_="inputerror")
+ if "read_only" in attrs:
+ attrs["disabled"] = "disabled" if
attrs.pop("read_only") else None
+ self.hidden_field(varname, current, add_var=False)
+
self.open_select(name=varname, id_=varname, **attrs)
for value, text in chs:
# if both the default in choices and current was '' then selected
depended on the order in choices
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 91534c9..dba9eee 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1591,6 +1591,7 @@ class DropdownChoice(ValueSpec):
self._no_preselect_title = kwargs.get("no_preselect_title",
"") # if not preselected
self._no_preselect_error = kwargs.get("no_preselect_error",
_("Please make a selection"))
self._on_change = kwargs.get("on_change")
+ self._read_only = kwargs.get("read_only", False)
def choices(self):
result = []
@@ -1644,7 +1645,10 @@ class DropdownChoice(ValueSpec):
deflt=self.option_id(defval))
else:
html.dropdown(varprefix, self._options_for_html(options),
- deflt=self.option_id(defval),onchange=self._on_change,
sorted=self._sorted)
+ deflt=self.option_id(defval),
+ onchange=self._on_change,
+ sorted=self._sorted,
+ read_only=self._read_only)
def _get_invalid_choice_title(self, value):