From 972bce47dc2d9aedf1992a3eb9b10af3c7291b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Tue, 4 Apr 2023 10:03:09 +0200 Subject: [PATCH] ENH: allow to provide a function that creates the form to create_show_form_callback --- src/core/js/form_panel.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/js/form_panel.js b/src/core/js/form_panel.js index 9728a4cc..a6c204d7 100644 --- a/src/core/js/form_panel.js +++ b/src/core/js/form_panel.js @@ -67,13 +67,26 @@ var form_panel = new function () { /** * Creates a callback function that toggles the form panel which */ - this.create_show_form_callback = function (panel_id, title, form_config) { + this.create_show_form_callback = function ( + panel_id, title, form_config, form_creator=undefined + ) { return (e) => { logger.trace("enter show_form_panel", e); const panel = $(form_panel.get_form_panel(panel_id, title)); if (panel.find("form").length === 0) { - const form = form_elements.make_form(form_config); + if (form_config != undefined && form_creator!=undefined){ + throw new Error("create_show_form_callback takes either a FormConfig or a function that creates the form"); + } + + var form; + if (form_config != undefined ){ + form = form_elements.make_form(form_config); + } else if (form_creator != undefined ){ + form = form_creator(); + } else { + throw new Error("create_show_form_callback takes a FormConfig or a function that creates the form"); + } panel.append(form); $(form).find(".selectpicker").selectpicker(); -- GitLab