Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Button: Remove add-hidden-input code and move it to nav vclick handle…

…r to cover non-enhanced buttons. Fixes #5387.
  • Loading branch information...
commit 1eadca872e004508f422646f2dac8e74b64ad80e 1 parent f60c3a8
@gabrielschulhof gabrielschulhof authored
Showing with 24 additions and 27 deletions.
  1. +24 −0 js/jquery.mobile.navigation.js
  2. +0 −27 js/widgets/forms/button.js
View
24 js/jquery.mobile.navigation.js
@@ -986,6 +986,25 @@ define( [
return path.makeUrlAbsolute( url, base);
}
+ function maybeCreateHiddenInput( $el ) {
+ var type = $el.attr( "type" ),
+ name = $el.attr( "name" );
+
+ if ( type !== "button" && type !== "reset" && name ) {
+ // Add hidden input so the value of the clicked button will be recorded
+ // in the submitted form data, but remove the hidden input from the form
+ // after the value has been recorded so as to avoid multiple copies of it
+ // preceding the original button.
+ $.mobile.document.one( "submit",
+ $.proxy( function() { this.remove(); },
+ $( "<input>", {
+ type: "hidden",
+ name: $el.attr( "name" ),
+ value: $el.attr( "value" )
+ }).insertBefore( $el ) ) );
+ }
+ }
+
//The following event bindings should be bound after mobileinit has been triggered
//the following deferred is resolved in the init file
$.mobile.navreadyDeferred = $.Deferred();
@@ -1063,6 +1082,11 @@ define( [
return;
}
+ // If this is a vclick on a button, we must make sure its value will be
+ // recorded in the resulting form data by adding a hidden input that
+ // carries the button's value
+ maybeCreateHiddenInput( $( target ) );
+
// Try to find a target element to which the active class will be applied
if ( $.data( target, "mobile-button" ) ) {
// If the form will not be submitted via AJAX, do not add active class
View
27 js/widgets/forms/button.js
@@ -36,8 +36,6 @@ $.widget( "mobile.button", $.mobile.widget, {
return ret;
} )( this.options ),
- type,
- name,
classes = "",
$buttonPlaceholder;
@@ -81,31 +79,6 @@ $.widget( "mobile.button", $.mobile.widget, {
.append( $el.addClass( "ui-btn-hidden" ) );
$button = this.button;
- type = $el.attr( "type" );
- name = $el.attr( "name" );
-
- // Add hidden input during submit if input type="submit" has a name.
- if ( type !== "button" && type !== "reset" && name ) {
- $el.bind( "vclick", function() {
- // Add hidden input if it doesn't already exist.
- if ( $buttonPlaceholder === undefined ) {
- $buttonPlaceholder = $( "<input>", {
- type: "hidden",
- name: $el.attr( "name" ),
- value: $el.attr( "value" )
- }).insertBefore( $el );
-
- // Bind to doc to remove after submit handling
- $.mobile.document.one( "submit", function() {
- $buttonPlaceholder.remove();
-
- // reset the local var so that the hidden input
- // will be re-added on subsequent clicks
- $buttonPlaceholder = undefined;
- });
- }
- });
- }
$el.bind({
focus: function() {
Please sign in to comment.
Something went wrong with that request. Please try again.