From 6a31c0a6e011ef8996e57a2d925510522fab56bb Mon Sep 17 00:00:00 2001
From: Ted Trask
Date: Wed, 8 Dec 2010 13:43:06 +0000
Subject: Fix viewfunctions for select/multi to display the label of the
default, not the value.
---
lib/viewfunctions.lua | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
(limited to 'lib/viewfunctions.lua')
diff --git a/lib/viewfunctions.lua b/lib/viewfunctions.lua
index bcb8a2c..d7d25f8 100644
--- a/lib/viewfunctions.lua
+++ b/lib/viewfunctions.lua
@@ -1,6 +1,25 @@
require("html")
require("session")
+function getlabel(myitem, value)
+ if myitem and (myitem.type == "select" or myitem.type == "multi") then
+ for x,val in ipairs(myitem.option) do
+ local v,l
+ if type(val) == "string" then
+ v = val
+ l = val
+ else
+ v = val.value
+ l = val.label
+ end
+ if v == value then
+ return l
+ end
+ end
+ end
+ return value
+end
+
function displayitem(myitem)
if not myitem then return end
io.write("' .. string.gsub(html.html_escape(myitem.descr), "\n", "
") .. "
\n") end
- if myitem.default then io.write('Default:' .. string.gsub(html.html_escape(myitem.default), "\n", "
") .. "
\n") end
+ if myitem.default then io.write('Default:' .. string.gsub(html.html_escape(getlabel(myitem, myitem.default)), "\n", "
") .. "
\n") end
if myitem.errtxt then io.write('' .. string.gsub(html.html_escape(myitem.errtxt), "\n", "
") .. "
\n") end
io.write("\n")
end
--
cgit v1.2.3