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