Skip to content
Snippets Groups Projects

ENH: allow to provide a function that creates the form to create_show_form_callback

Merged Henrik tom Wörden requested to merge f-edit-panel into dev
All threads resolved!
Files
3
+ 19
2
@@ -66,14 +66,31 @@ var form_panel = new function () {
/**
* Creates a callback function that toggles the form panel which
*
* You may supply 'undefined' as form_config and use form_creator
* instead which is supposed to be a function without argument that
* return the form to be added to the panel
*/
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();
Loading