Permalink
Browse files

- Fixed issue #1923 - url of form is miscalculated

	- Added code to calculate whether to choose the documentUrl or the page Url in the case where an action is not specified on a form element.

	- Fixed bug in the navigation "submit" handler where an error was being thrown if "type" was not specified.

	- Fixed typo "diabled" id typos in tests/unit/navigation/index.html.

	- Added tests for form submissions with no action in both base and non-base specified cases.
  • Loading branch information...
1 parent e8a973f commit 0d65a0d1c549c5e10b08d74de88f21737b7d9482 @jblas jblas committed Jun 27, 2011
@@ -967,8 +967,27 @@
}
var type = $this.attr( "method" ),
- url = path.makeUrlAbsolute( $this.attr( "action" ), getClosestBaseUrl($this) ),
- target = $this.attr( "target" );
+ target = $this.attr( "target" ),
+ url = $this.attr( "action" );
+
+ // If no action is specified, browsers default to using the
+ // URL of the document containing the form. Since we dynamically
+ // pull in pages from external documents, the form should submit
+ // to the URL for the source document of the page containing
+ // the form.
+ if ( !url ) {
+ // Get the @data-url for the page containing the form.
+ url = getClosestBaseUrl( $this );
+ if ( url === documentBase.hrefNoHash ) {
+ // The url we got back matches the document base,
+ // which means the page must be an internal/embedded page,
+ // so default to using the actual document url as a browser
+ // would.
+ url = documentUrl.hrefNoSearch;
+ }
+ }
+
+ url = path.makeUrlAbsolute( url, getClosestBaseUrl($this) );
//external submits use regular HTTP
if( path.isExternal( url ) || target ) {
@@ -978,7 +997,7 @@
$.mobile.changePage(
url,
{
- type: type.length && type.toLowerCase() || "get",
+ type: type && type.length && type.toLowerCase() || "get",
data: $this.serialize(),
transition: $this.jqmData( "transition" ),
direction: $this.jqmData( "direction" ),
@@ -55,5 +55,14 @@ <h2 id="qunit-userAgent"></h2>
<img src="images/internal-page-2.png">
</div>
+<div data-nstest-role="page" id="internal-no-action-form-page">
+ <div data-nstest-role="content">
+ <form>
+ <input type="hidden" name="foo" value="1">
+ <input type="hidden" name="bar" value="2">
+ </form>
+ </div>
+</div>
+
</body>
</html>
@@ -9,6 +9,11 @@
<a href="../../#internal-page-1" class="ip1">Internal Page 1</a>
<a href="../../#internal-page-2" class="ip2">Internal Page 2</a>
<img src="images/content-page-1.png">
+
+ <form>
+ <input type="hidden" name="foo" value="1">
+ <input type="hidden" name="bar" value="2">
+ </form>
</div>
</body>
</html>
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+<div id="external-form-no-action-page" data-nstest-role="page">
+ <div data-nstest-role="content">
+ <form>
+ <input type="hidden" name="foo" value="1">
+ <input type="hidden" name="bar" value="2">
+ </form>
+ </div>
+</div>
+</body>
+</html>
@@ -83,11 +83,11 @@ <h2 id="qunit-userAgent"></h2>
<a href="data-url-tests/reverse-attr.html"></a>
</div>
-<div id="ajax-diabled-form" data-nstest-role="page">
+<div id="ajax-disabled-form" data-nstest-role="page">
<form method="POST" id="non-ajax-form" action="/ajax-disabled-form" data-nstest-ajax="false">
</form>
- <form method="POST" id="ajax-form" action="/ajax-diabled-form">
+ <form method="POST" id="ajax-form" action="/ajax-disabled-form">
</form>
<form method="POST" id="rand-ajax-form" action="/ajax-disabled-form" data-nstest-ajax="foo">
@@ -229,5 +229,17 @@ <h2 id="qunit-userAgent"></h2>
<div data-nstest-role="page" id="pathing-tests-reset">
<div class="reset-value">page didn't change!</div>
</div>
+
+<div data-nstest-role="page" id="internal-no-action-form-page">
+ <div data-nstest-role="content">
+ <form>
+ <input type="hidden" name="foo" value="1">
+ <input type="hidden" name="bar" value="2">
+ </form>
+ <a href="form-tests/form-no-action.html">External page containing form with no action.</a>
+ </div>
+</div>
+
+
</body>
</html>
@@ -111,4 +111,45 @@
start();
}]);
});
+
+ asyncTest( "internal form with no action submits to document URL", function(){
+
+ $.testHelper.pageSequence([
+ // open our test page
+ function(){
+ $.testHelper.openPage("#internal-no-action-form-page");
+ },
+
+ function(){
+ $("#internal-no-action-form-page form").eq(0).submit();
+ },
+
+ function(){
+ same(location.hash, "#" + location.pathname + "?foo=1&bar=2", "hash should match document url and not base url");
+ start();
+ }
+ ]);
+ });
+
+ asyncTest( "external page form with no action submits to external page URL", function(){
+ $.testHelper.pageSequence([
+ function(){
+ // Go to an external page that has a form.
+ $("#internal-page-1 .cp1").click();
+ },
+
+ function(){
+ // Make sure we actually navigated to the external page.
+ same(location.hash, "#" + contentDir + "content-page-1.html", "should be on content-page-1.html");
+
+ // Now submit the form in the external page.
+ $("#content-page-1 form").eq(0).submit();
+ },
+
+ function(){
+ same(location.hash, "#" + contentDir + "content-page-1.html?foo=1&bar=2", "hash should match page url and not document url");
+ start();
+ }]);
+ });
+
})(jQuery);
@@ -493,4 +493,46 @@
}
]);
});
+
+ asyncTest( "internal form with no action submits to document URL", function(){
+
+ $.testHelper.pageSequence([
+ // open our test page
+ function(){
+ $.testHelper.openPage("#internal-no-action-form-page");
+ },
+
+ function(){
+ $("#internal-no-action-form-page form").eq(0).submit();
+ },
+
+ function(){
+ same(location.hash, "#" + location.pathname + "?foo=1&bar=2", "hash should match what was loaded");
+ start();
+ }
+ ]);
+ });
+
+ asyncTest( "external page containing form with no action submits to page URL", function(){
+
+ $.testHelper.pageSequence([
+ // open our test page
+ function(){
+ $.testHelper.openPage("#internal-no-action-form-page");
+ },
+
+ function(){
+ $("#internal-no-action-form-page a").eq(0).click();
+ },
+
+ function(){
+ $("#external-form-no-action-page form").eq(0).submit();
+ },
+
+ function(){
+ same(location.hash, "#" + siteDirectory + "form-tests/form-no-action.html?foo=1&bar=2", "hash should match page url and not document url");
+ start();
+ }
+ ]);
+ });
})(jQuery);

0 comments on commit 0d65a0d

Please sign in to comment.