# HG changeset patch # User Kim Alvefur # Date 1533326740 -7200 # Node ID 519dea077d20a2c07338810a5add4580b8821024 # Parent 56c52cb4d44ecdd359ccdafc9735aa1d89681484 util.dataforms: Allow passing dynamically generated options as values (fixes traceback) This is awkward but there’s currently no better way to do this, short of dynamically generating the entire form each time diff -r 56c52cb4d44e -r 519dea077d20 util/dataforms.lua --- a/util/dataforms.lua Fri Aug 03 21:45:55 2018 +0200 +++ b/util/dataforms.lua Fri Aug 03 22:05:40 2018 +0200 @@ -57,9 +57,16 @@ 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