Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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
Wilto committed Sep 23, 2011
1 parent dec502d commit ecc1361
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions js/jquery.mobile.forms.button.js
Expand Up @@ -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>" )
Expand All @@ -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();
Expand Down

0 comments on commit ecc1361

Please sign in to comment.