Changeset

9091:519dea077d20

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
author Kim Alvefur <zash@zash.se>
date Fri, 03 Aug 2018 22:05:40 +0200
parents 9090:56c52cb4d44e
children 9092:5110da3a71eb
files util/dataforms.lua
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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