From c6db698f654bc19e112f6106e464ab97d8d78e1a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 27 May 2016 15:44:41 +0200 Subject: util.dataforms: Allow separation of options from values in list fields --- util/dataforms.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'util/dataforms.lua') diff --git a/util/dataforms.lua b/util/dataforms.lua index 79b4d1a4..685f3aaf 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -69,10 +69,10 @@ function form_t.form(layout, data, formtype) end elseif field_type == "list-single" then local has_default = false; - for _, val in ipairs(value) do + for _, val in ipairs(field.options or value) do if type(val) == "table" then form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); - if val.default and (not has_default) then + if value == val.value or field.options and val.default and (not has_default) then form:tag("value"):text(val.value):up(); has_default = true; end @@ -80,17 +80,25 @@ function form_t.form(layout, data, formtype) form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end end + if field.options and value then + form:tag("value"):text(value):up(); + end elseif field_type == "list-multi" then - for _, val in ipairs(value) do + for _, val in ipairs(field.options or value) do if type(val) == "table" then form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); - if val.default then + if not field.options and val.default then form:tag("value"):text(val.value):up(); end else form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end end + if field.options and value then + for _, val in ipairs(value) do + form:tag("value"):text(val):up(); + end + end end end -- cgit v1.2.3