From 21870a90fa14b5d74c8cf2e01328d3129f1e7b17 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 28 Oct 2010 07:24:45 +0000 Subject: Modified html.select to allow specifying option value and label, also fix bug with multiselect. --- html.lua | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'html.lua') 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 .. "" + str = str .. nv_pair("value", val) .. ">" .. html_escape(label) .. "" end - if not selected then - str = str .. '' + for val in pairs(reverseval) do + str = str .. '' end str = str .. "" return (str) -- cgit v1.2.3