Ensure URL query string information is applied to anchor/go elements
CRs-Fixed: 648697
Issues-fixed: SWE-1848, CHNAPSS-1926
Change-Id: I53c9d9d378f974186bb3695d4fc8ed135d25dcad
diff --git a/assets/wml/swe_wml.js b/assets/wml/swe_wml.js
index 92fa6ee..5e98452 100755
--- a/assets/wml/swe_wml.js
+++ b/assets/wml/swe_wml.js
@@ -516,6 +516,39 @@
}
//<go>
+function addQueryStringKeyValuePairsToForm(form)
+{
+ var href = form.dataset.wml_href;
+ var query;
+
+ // Seperate the query string from the href
+ var queryFragments = href.split("?");
+ if (queryFragments.length === 2) {
+ query = queryFragments[1];
+ } else {
+ queryFragments.shift();
+ query = queryFragments.join("?");
+ }
+
+ // Parse the query string for key/value pairs. Add them to the form
+ // as hidden input elements.
+ // E.g., http://myserver/test.wml?p1=foo&p2=bar
+ // would add the following to the form:
+ // <input type="hidden" name="p1" value="foo">
+ // <input type="hidden" name="p2" value="bar">
+ query.replace(
+ new RegExp( "([^?=&]+)(?:=([^&]*))?", "g" ),
+ function(match, name, value) {
+ var param = document.createElement("input");
+ param.setAttribute("type","hidden")
+ param.setAttribute("name", name)
+ param.setAttribute("value",value)
+ form.appendChild(param)
+ }
+ );
+ return true;
+}
+
function internal_executeGoTask(form)
{
var href = form.dataset.wml_href;
@@ -528,6 +561,7 @@
}
// Substitute variables in <postfield> 'value' attributes before form submission.
updateVariableInPostfields();
+ addQueryStringKeyValuePairsToForm(form);
form.submit();
return false;
}