Add the option to use FormData to encode the form elements
If the form's enctype attribute is set to "multipart/form-data", use FormData to encode the form's elements.
This commit is contained in:
@@ -31,6 +31,22 @@ var formAction = function(el, event) {
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
if (el.enctype === "multipart/form-data") {
|
||||
options.requestOptions.formData = new FormData(el)
|
||||
}
|
||||
else {
|
||||
options.requestOptions.requestParams = parseFormElements(el)
|
||||
}
|
||||
|
||||
el.setAttribute(attrState, "submit")
|
||||
|
||||
options.triggerElement = el
|
||||
this.loadUrl(virtLinkElement.href, options)
|
||||
}
|
||||
|
||||
function parseFormElements(el) {
|
||||
var requestParams = []
|
||||
|
||||
for (var elementKey in el.elements) {
|
||||
if (Number.isNaN(Number(elementKey))) {
|
||||
continue;
|
||||
@@ -62,7 +78,7 @@ var formAction = function(el, event) {
|
||||
}
|
||||
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
options.requestOptions.requestParams.push({
|
||||
requestParams.push({
|
||||
name: encodeURIComponent(element.name),
|
||||
value: encodeURIComponent(values[j])
|
||||
})
|
||||
@@ -71,10 +87,7 @@ var formAction = function(el, event) {
|
||||
}
|
||||
}
|
||||
|
||||
el.setAttribute(attrState, "submit")
|
||||
|
||||
options.triggerElement = el
|
||||
this.loadUrl(virtLinkElement.href, options)
|
||||
return requestParams
|
||||
}
|
||||
|
||||
function checkIfShouldAbort(virtLinkElement, options) {
|
||||
|
||||
@@ -51,6 +51,9 @@ module.exports = function(location, options, callback) {
|
||||
break
|
||||
}
|
||||
}
|
||||
else if (requestOptions.formData) {
|
||||
requestPayload = requestOptions.formData
|
||||
}
|
||||
|
||||
// Add a timestamp as part of the query string if cache busting is enabled
|
||||
if (options.cacheBust) {
|
||||
|
||||
Reference in New Issue
Block a user