Refactor query string building
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user