Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

For the sake of jQuery’s serialize, submit inputs’ values are added t…

…o the form as a hidden input—this ensures it will only happen once, and that this logic only applies to submit inputs with a name attribute.
  • Loading branch information...
commit ecc1361f7f969e893d209387028acfd5bd6abc41 1 parent dec502d
@Wilto Wilto authored
Showing with 20 additions and 16 deletions.
  1. +20 −16 js/jquery.mobile.forms.button.js
View
36 js/jquery.mobile.forms.button.js
@@ -21,7 +21,9 @@ $.widget( "mobile.button", $.mobile.widget, {
_create: function() {
var $el = this.element,
o = this.options,
- type;
+ type,
+ name,
+ $buttonPlaceholder;
// Add ARIA role
this.button = $( "<div></div>" )
@@ -38,25 +40,27 @@ $.widget( "mobile.button", $.mobile.widget, {
.insertBefore( $el )
.append( $el.addClass( "ui-btn-hidden" ) );
- // Add hidden input during submit
type = $el.attr( "type" );
+ name = $el.attr( "name" );
- if ( type !== "button" && type !== "reset" ) {
+ // 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 );
- $el.bind( "vclick", function() {
-
- var $buttonPlaceholder = $( "<input>", {
- type: "hidden",
- name: $el.attr( "name" ),
- value: $el.attr( "value" )
- })
- .insertBefore( $el );
-
- // Bind to doc to remove after submit handling
- $( document ).submit(function(){
- $buttonPlaceholder.remove();
+ // Bind to doc to remove after submit handling
+ $( document ).submit(function(){
+ $buttonPlaceholder.remove();
+ });
+ }
});
- });
}
this.refresh();
Please sign in to comment.
Something went wrong with that request. Please try again.