From 414778ee5d861e9e23dd54a690cc341ba98b658c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 3 Aug 2018 22:05:40 +0200 Subject: util.dataforms: Allow passing dynamically generated options as values (fixes traceback) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is awkward but there’s currently no better way to do this, short of dynamically generating the entire form each time --- util/dataforms.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/dataforms.lua b/util/dataforms.lua index 649676f8..45f1a79a 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -57,9 +57,16 @@ function form_t.form(layout, data, formtype) value = field.value; end - if formtype == "form" and field.options then + local options = field.options; + if formtype == "form" and not options and value + and (field_type == "list-single" or field_type == "list-multi") then + -- Allow passing dynamically generated options as values + options, value = value, nil; + end + + if formtype == "form" and options then local defaults = {}; - for _, val in ipairs(field.options) do + for _, val in ipairs(options) do if type(val) == "table" then form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); if val.default then -- cgit v1.2.3