diff --git a/the_works/static/the_works.js b/the_works/static/the_works.js
index 10a1f40..ad2bd90 100644
--- a/the_works/static/the_works.js
+++ b/the_works/static/the_works.js
@@ -14,7 +14,6 @@ function initDataTable(table_id) {
// create "New"-element and append it to the
containing the DataTables search field
function initCreateButton(opts) {
-console.log(`initCreateButton: opts are ${JSON.stringify(opts)}`);
let a = document.createElement("a");
a.id = "create-button";
a.setAttribute("title", opts.title);
@@ -25,14 +24,23 @@ console.log(`initCreateButton: opts are ${JSON.stringify(opts)}`);
}
function showDialog(opts) {
- console.log(`showDialog: opts are ${JSON.stringify(opts)}`);
// if form action includes the string "update", the id at the end of the URL is a dummy and must be replaced with the correct id
if ( opts.url_id && opts.form_action.includes("update") ) {
opts.form_action = opts.form_action.slice(0, opts.form_action.lastIndexOf("/") + 1) + opts.url_id;
}
- console.log(`showDialog: opts.form_action is ${opts.form_action}`);
+ // if input id or input value is not an array, make it a single-element array
+ opts.input_id = Array.isArray(opts.input_id) ? opts.input_id : [ opts.input_id ];
+ if ( opts.input_value ) {
+ opts.input_value = Array.isArray(opts.input_value) ? opts.input_value : [ opts.input_value ];
+ } else {
+ opts.input_value = new Array(opts.input_id.length).fill("");
+ }
+
+ console.log(`id[] is ${JSON.stringify(opts.input_id)}, value[] is ${JSON.stringify(opts.input_value)}`);
document.getElementById("dialog-heading").textContent = opts.heading;
- document.getElementById(opts.input_id).value = opts.input_value || "";
+ for (var i = 0; i < opts.input_id.length; i++ ) {
+ document.getElementById(opts.input_id[i]).value = opts.input_value[i] || "";
+ }
document.getElementById("form_submit").formAction = opts.form_action;
document.getElementById(opts.modal_id).showModal();
}