Refactor query string building

This commit is contained in:
Robin North
2018-03-01 10:19:35 +00:00
parent ca479618fe
commit 4e805ad8af
2 changed files with 16 additions and 13 deletions

View File

@@ -11,7 +11,8 @@ var formAction = function(el, event) {
// Initialize requestOptions
options.requestOptions = {
requestUrl: el.getAttribute("action") || window.location.href,
requestMethod: el.getAttribute("method") || "GET"
requestMethod: el.getAttribute("method") || "GET",
requestParams: []
}
// create a testable virtual link of the form action
@@ -44,20 +45,20 @@ var formAction = function(el, event) {
event.preventDefault()
var params = []
for (var elementKey in el.elements) {
var element = el.elements[elementKey]
// jscs:disable disallowImplicitTypeConversion
if (!!element.name && element.attributes !== undefined && element.tagName.toLowerCase() !== "button") {
// jscs:enable disallowImplicitTypeConversion
if ((!element.attributes.type || element.attributes.type.value !== "checkbox" && element.attributes.type.value !== "radio") || element.checked) {
params.push({name: encodeURIComponent(element.name), value: encodeURIComponent(element.value)})
options.requestOptions.requestParams.push({
name: encodeURIComponent(element.name),
value: encodeURIComponent(element.value)
})
}
}
}
options.requestOptions.requestParams = params
el.setAttribute(attrClick, "submit")
options.triggerElement = el