From 569c929cd2a452f8d44b1f7e02e95f10e0d34dc8 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 20 Feb 2020 16:58:02 +0000 Subject: Add optgroup support to select input --- html.lua | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'html.lua') diff --git a/html.lua b/html.lua index 425fd0b..5bb46a6 100644 --- a/html.lua +++ b/html.lua @@ -193,7 +193,8 @@ end -- v.value is the selected item (or an array if multiple) --- v.option is an array of valid options (or an array of value, label) +-- v.option is an array of valid string options or an array of {value, label} +-- v.option can also contain optgroups (table containing above) -- NOTE use of value and values (plural) function mymodule.form.select ( v ) if ( v.name == nil ) then @@ -224,21 +225,34 @@ function mymodule.form.select ( v ) else reverseval[v.value]=1 end - for i, k in ipairs ( v.option ) do + local displayoption = function(opt) local val, label - if type(k) == "string" then - val = k - label = k - else - val = k.value - label = k.label + if type(opt) == "string" then + val = opt + label = opt + elseif type(opt.value) == "string" then + val = opt.value + label = opt.label + end + if val then + str = str .. "" end - str = str .. "" end for val in pairs(reverseval) do str = str .. '' -- cgit v1.2.3