Fix form submit/data bugs

This commit is contained in:
Dennis Eichhorn 2019-02-23 19:10:08 +01:00
parent 46b87aa55a
commit b9b339d39a
2 changed files with 23 additions and 13 deletions

View File

@ -130,7 +130,13 @@
*/ */
bindExport(exports) bindExport(exports)
{ {
exports.getExport().addEventListener('click', function (event) const button = exports.getExport();
if (typeof button === 'undefined' || button === null) {
return;
}
button.addEventListener('click', function (event)
{ {
console.log(exports.serialize()); console.log(exports.serialize());
// todo: either create download in javascript from this data or make roundtrip to server who then sends the data // todo: either create download in javascript from this data or make roundtrip to server who then sends the data

View File

@ -176,7 +176,8 @@
buttons = form.getElementsByTagName('button'), buttons = form.getElementsByTagName('button'),
canvas = form.getElementsByTagName('canvas'), canvas = form.getElementsByTagName('canvas'),
external = document.querySelectorAll('[form=' + this.id + ']'), external = document.querySelectorAll('[form=' + this.id + ']'),
special = document.querySelectorAll('[data-form=' + this.id + '] [data-name]'), special = form.querySelectorAll('[data-name]'),
specialExt = document.querySelectorAll('[data-form=' + this.id + '] [data-name]'),
inputLength = inputs.length; inputLength = inputs.length;
// todo: handle trigger element. check which element triggered the submit and pass it's name+value // todo: handle trigger element. check which element triggered the submit and pass it's name+value
@ -192,15 +193,14 @@
// todo: handle radio here as well // todo: handle radio here as well
} }
return this.getUniqueFormElements( return Array.prototype.slice.call(inputs).concat(
Array.prototype.slice.call(inputs).concat( Array.prototype.slice.call(selects),
Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas),
Array.prototype.slice.call(textareas), Array.prototype.slice.call(buttons),
Array.prototype.slice.call(buttons), Array.prototype.slice.call(external),
Array.prototype.slice.call(external), Array.prototype.slice.call(special),
Array.prototype.slice.call(special) Array.prototype.slice.call(specialExt)
) ).filter(function(val) { return val; });
);
}; };
/** /**
@ -247,8 +247,12 @@
} }
} }
// handle array data (e.g. table rows with same name)
const id = jsOMS.Views.FormView.getElementId(elements[i]); const id = jsOMS.Views.FormView.getElementId(elements[i]);
if (id === null) {
continue;
}
// handle array data (e.g. table rows with same name)
if (data.hasOwnProperty(id)) { if (data.hasOwnProperty(id)) {
if (data[id].constructor !== Array) { if (data[id].constructor !== Array) {
data[id] = [data[id]]; data[id] = [data[id]];
@ -335,7 +339,7 @@
return e.getAttribute('type'); return e.getAttribute('type');
} }
throw Error("Invalid id"); return null;
}; };
/** /**