Working but incomplete
This commit is contained in:
parent
763499f9e3
commit
780c99259f
@ -30,6 +30,8 @@
|
|||||||
var massInputFormSubmitHandler;
|
var massInputFormSubmitHandler;
|
||||||
var massInputForm;
|
var massInputForm;
|
||||||
|
|
||||||
|
var massInputEnctype;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (!element) {
|
if (!element) {
|
||||||
throw new Error('Mass Input utility cannot be setup without an element!');
|
throw new Error('Mass Input utility cannot be setup without an element!');
|
||||||
@ -62,7 +64,7 @@
|
|||||||
|
|
||||||
var method = massInputForm.getAttribute('method') || 'POST';
|
var method = massInputForm.getAttribute('method') || 'POST';
|
||||||
var url = massInputForm.getAttribute('action') || window.location.href;
|
var url = massInputForm.getAttribute('action') || window.location.href;
|
||||||
var enctype = massInputForm.getAttribute('enctype') || 'application/json';
|
massInputEnctype = massInputForm.getAttribute('enctype') || 'application/json';
|
||||||
|
|
||||||
var requestFn;
|
var requestFn;
|
||||||
if (HttpClient[method.toLowerCase()]) {
|
if (HttpClient[method.toLowerCase()]) {
|
||||||
@ -84,7 +86,7 @@
|
|||||||
requestFn(
|
requestFn(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
'Content-Type': enctype,
|
'Content-Type': massInputEnctype,
|
||||||
'Mass-Input-Shortcircuit': massInputId,
|
'Mass-Input-Shortcircuit': massInputId,
|
||||||
},
|
},
|
||||||
requestBody,
|
requestBody,
|
||||||
@ -109,15 +111,23 @@
|
|||||||
|
|
||||||
function serializeForm() {
|
function serializeForm() {
|
||||||
var formData = new FormData(massInputForm);
|
var formData = new FormData(massInputForm);
|
||||||
var formBody = [];
|
|
||||||
|
|
||||||
for(var formField of formData) {
|
Array.from(element.querySelectorAll('button:focus, button:active')).forEach(function (el) {
|
||||||
var encodedKey = encodeURIComponent(formField[0]);
|
if (!el.name || !el.value)
|
||||||
var encodedValue = encodeURIComponent(formField[1]);
|
return;
|
||||||
formBody.push(encodedKey + "=" + encodedValue);
|
|
||||||
|
console.log(el);
|
||||||
|
|
||||||
|
formData.append(el.name, el.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (massInputEnctype === 'application/x-www-form-urlencoded') {
|
||||||
|
return new URLSearchParams(formData);
|
||||||
|
} else if (massInputEnctype === 'multipart/form-data') {
|
||||||
|
return formData;
|
||||||
|
} else {
|
||||||
|
throw new Error('Unsupported form enctype: ' + massInputEnctype);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formBody.join("&");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
|
|||||||
Reference in New Issue
Block a user