Clone options before modifying it for form submissions
This commit is contained in:
@@ -6,14 +6,18 @@ var clone = require("../clone")
|
||||
var attrClick = "data-pjax-click-state"
|
||||
|
||||
var formAction = function(el, event) {
|
||||
this.options.requestOptions = {
|
||||
// Since we'll be modifying request options, clone the existing options
|
||||
// so these changes don't persist
|
||||
var options = clone(this.options);
|
||||
|
||||
options.requestOptions = {
|
||||
requestUrl: el.getAttribute("action") || window.location.href,
|
||||
requestMethod: el.getAttribute("method") || "GET",
|
||||
}
|
||||
|
||||
// create a testable virtual link of the form action
|
||||
var virtLinkElement = document.createElement("a");
|
||||
virtLinkElement.setAttribute("href", this.options.requestOptions.requestUrl);
|
||||
virtLinkElement.setAttribute("href", options.requestOptions.requestUrl);
|
||||
|
||||
// Ignore external links.
|
||||
if (virtLinkElement.protocol !== window.location.protocol || virtLinkElement.host !== window.location.host) {
|
||||
@@ -34,7 +38,7 @@ var formAction = function(el, event) {
|
||||
}
|
||||
|
||||
// if declared as a full reload, just normally submit the form
|
||||
if (this.options.currentUrlFullReload) {
|
||||
if (options.currentUrlFullReload) {
|
||||
el.setAttribute(attrClick, "reload");
|
||||
return;
|
||||
}
|
||||
@@ -56,12 +60,12 @@ var formAction = function(el, event) {
|
||||
// Creating a getString
|
||||
var paramsString = (paramObject.map(function(value) {return value.name + "=" + value.value;})).join("&");
|
||||
|
||||
this.options.requestOptions.requestPayload = paramObject;
|
||||
this.options.requestOptions.requestPayloadString = paramsString;
|
||||
options.requestOptions.requestPayload = paramObject;
|
||||
options.requestOptions.requestPayloadString = paramsString;
|
||||
|
||||
el.setAttribute(attrClick, "submit");
|
||||
|
||||
var options = clone(this.options);
|
||||
|
||||
options.triggerElement = el;
|
||||
this.loadUrl(virtLinkElement.href, options);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user