summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2010-10-28 07:24:45 +0000
committerTed Trask <ttrask01@yahoo.com>2010-10-28 07:24:45 +0000
commit21870a90fa14b5d74c8cf2e01328d3129f1e7b17 (patch)
tree576426b8b898c008e0296e64a5bf5a9f5bb559ee
parente3e7d721f2a55028101aef7e2fdbe2df490a4871 (diff)
downloadacf-lib-21870a90fa14b5d74c8cf2e01328d3129f1e7b17.tar.bz2
acf-lib-21870a90fa14b5d74c8cf2e01328d3129f1e7b17.tar.xz
Modified html.select to allow specifying option value and label, also fix bug with multiselect.
-rw-r--r--html.lua32
1 files changed, 15 insertions, 17 deletions
diff --git a/html.lua b/html.lua
index 33d6d71..fc34f17 100644
--- a/html.lua
+++ b/html.lua
@@ -159,7 +159,7 @@ end
-- v.value is the selected item (or an array if multiple)
--- v.option is an array of valid options
+-- v.option is an array of valid options (or an array of value, label)
-- NOTE use of value and values (plural)
function form.select ( v )
if ( v.name == nil ) then
@@ -184,29 +184,27 @@ function form.select ( v )
for x,val in ipairs(v.value) do
reverseval[val]=x
end
+ else
+ reverseval[v.value]=1
end
- local selected = false
for i, k in ipairs ( v.option ) do
- local val = k
- local txt = nil
- if type(val) == "table" then
- txt=val[1]
- val=val[0]
+ local val, label
+ if type(k) == "string" then
+ val = k
+ label = k
+ else
+ val = k.value
+ label = k.label
end
str = str .. "<option "
- if type(v.value) == "table" then
- if reverseval[val] then
- str = str .. " selected"
- selected = true
- end
- elseif ( v.value == val ) then
+ if reverseval[val] then
str = str .. " selected"
- selected = true
+ reverseval[val] = nil
end
- str = str .. nv_pair("value", val) .. ">" .. html_escape(val) .. "</option>"
+ str = str .. nv_pair("value", val) .. ">" .. html_escape(label) .. "</option>"
end
- if not selected then
- str = str .. '<option selected value="' .. html_escape(v.value) ..'">[' .. html_escape(v.value) .. ']</option>'
+ for val in pairs(reverseval) do
+ str = str .. '<option selected value="' .. html_escape(val) ..'">[' .. html_escape(val) .. ']</option>'
end
str = str .. "</select>"
return (str)