Fix cart update field enter on submit for IE
Fix for issue #11811 https://github.com/woothemes/woocommerce/issues/11811 IE handles hitting <ENTER> on an input field differently than Chrome or Firefox in that it finds the nearest submit button and fires the event from it instead of the actual text field from which the user hit <ENTER>. This commit catches the <ENTER> key event before the submit happens and forces the cart_submit handling on that event instead.
This commit is contained in:
parent
e0572c782d
commit
81d186000d
|
@ -267,6 +267,7 @@ jQuery( function( $ ) {
|
|||
*/
|
||||
init: function() {
|
||||
this.update_cart_totals = this.update_cart_totals.bind( this );
|
||||
this.input_keypress = this.input_keypress.bind( this );
|
||||
this.cart_submit = this.cart_submit.bind( this );
|
||||
this.submit_click = this.submit_click.bind( this );
|
||||
this.apply_coupon = this.apply_coupon.bind( this );
|
||||
|
@ -282,6 +283,10 @@ jQuery( function( $ ) {
|
|||
'click',
|
||||
'div.woocommerce > form input[type=submit]',
|
||||
this.submit_click );
|
||||
$( document ).on(
|
||||
'keypress',
|
||||
'div.woocommerce > form input[type=number]',
|
||||
this.input_keypress );
|
||||
$( document ).on(
|
||||
'submit',
|
||||
'div.woocommerce:not(.widget_product_search) > form',
|
||||
|
@ -352,15 +357,40 @@ jQuery( function( $ ) {
|
|||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle the <ENTER> key for quantity fields.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*
|
||||
* For IE, if you hit enter on a quantity field, it makes the
|
||||
* document.activeElement the first submit button it finds.
|
||||
* For us, that is the Apply Coupon button. This is required
|
||||
* to catch the event before that happens.
|
||||
*/
|
||||
input_keypress: function( evt ) {
|
||||
|
||||
// Catch the enter key and don't let it submit the form.
|
||||
if ( 13 === evt.keyCode ) {
|
||||
evt.preventDefault();
|
||||
this.cart_submit( evt );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle cart form submit and route to correct logic.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*/
|
||||
cart_submit: function( evt ) {
|
||||
var $form = $( evt.currentTarget );
|
||||
var $submit = $( document.activeElement );
|
||||
var $clicked = $( 'input[type=submit][clicked=true]' );
|
||||
var $form = $( evt.currentTarget );
|
||||
|
||||
// For submit events, currentTarget is form.
|
||||
// For keypress events, currentTarget is input.
|
||||
if ( ! $form.is( 'form' ) ) {
|
||||
$form = $( evt.currentTarget ).parents( 'form' );
|
||||
}
|
||||
|
||||
if ( 0 === $form.find( '.shop_table.cart' ).length ) {
|
||||
return;
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue