Bind price and decimal input events to body in woocommerce_admin js
The event was bound to the element directly, causing problems when the elements was added after dom ready (through ajax). Now the decimal format check will always take place.
This commit is contained in:
parent
3d584bc09a
commit
e0dc31620b
|
@ -4,50 +4,47 @@
|
|||
jQuery(function(){
|
||||
|
||||
// Price input validation
|
||||
jQuery(".wc_input_decimal[type=text], .wc_input_price[type=text]")
|
||||
.bind( 'blur', function() {
|
||||
jQuery('body').on( 'blur', '.wc_input_decimal[type=text], .wc_input_price[type=text]', function() {
|
||||
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
|
||||
return this;
|
||||
});
|
||||
|
||||
jQuery(".wc_input_price[type=text]")
|
||||
.bind( 'keyup change', function() {
|
||||
var value = jQuery(this).val();
|
||||
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.mon_decimal_point + "]+", "gi" );
|
||||
var newvalue = value.replace( regex, '' );
|
||||
jQuery('body').on('keyup change', '.wc_input_price[type=text]', function(){
|
||||
var value = jQuery(this).val();
|
||||
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.mon_decimal_point + "]+", "gi" );
|
||||
var newvalue = value.replace( regex, '' );
|
||||
|
||||
if ( value !== newvalue ) {
|
||||
jQuery(this).val( newvalue );
|
||||
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
|
||||
var offset = jQuery(this).position();
|
||||
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_mon_decimal_error + '</div>' );
|
||||
jQuery('.wc_error_tip')
|
||||
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
|
||||
.css('top', offset.top + jQuery(this).height() )
|
||||
.fadeIn('100');
|
||||
}
|
||||
}
|
||||
return this;
|
||||
if ( value !== newvalue ) {
|
||||
jQuery(this).val( newvalue );
|
||||
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
|
||||
var offset = jQuery(this).position();
|
||||
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_mon_decimal_error + '</div>' );
|
||||
jQuery('.wc_error_tip')
|
||||
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
|
||||
.css('top', offset.top + jQuery(this).height() )
|
||||
.fadeIn('100');
|
||||
}
|
||||
}
|
||||
return this;
|
||||
});
|
||||
|
||||
jQuery(".wc_input_decimal[type=text]")
|
||||
.bind( 'keyup change', function() {
|
||||
var value = jQuery(this).val();
|
||||
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.decimal_point + "]+", "gi" );
|
||||
var newvalue = value.replace( regex, '' );
|
||||
jQuery('body').on('keyup change', '.wc_input_price[type=text]', function(){
|
||||
var value = jQuery(this).val();
|
||||
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.decimal_point + "]+", "gi" );
|
||||
var newvalue = value.replace( regex, '' );
|
||||
|
||||
if ( value !== newvalue ) {
|
||||
jQuery(this).val( newvalue );
|
||||
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
|
||||
var offset = jQuery(this).position();
|
||||
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_decimal_error + '</div>' );
|
||||
jQuery('.wc_error_tip')
|
||||
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
|
||||
.css('top', offset.top + jQuery(this).height() )
|
||||
.fadeIn('100');
|
||||
}
|
||||
}
|
||||
return this;
|
||||
if ( value !== newvalue ) {
|
||||
jQuery(this).val( newvalue );
|
||||
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
|
||||
var offset = jQuery(this).position();
|
||||
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_decimal_error + '</div>' );
|
||||
jQuery('.wc_error_tip')
|
||||
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
|
||||
.css('top', offset.top + jQuery(this).height() )
|
||||
.fadeIn('100');
|
||||
}
|
||||
}
|
||||
return this;
|
||||
});
|
||||
|
||||
jQuery("body").click(function(){
|
||||
|
@ -56,11 +53,11 @@ jQuery(function(){
|
|||
|
||||
// Tooltips
|
||||
jQuery(".tips, .help_tip").tipTip({
|
||||
'attribute' : 'data-tip',
|
||||
'fadeIn' : 50,
|
||||
'fadeOut' : 50,
|
||||
'delay' : 200
|
||||
});
|
||||
'attribute' : 'data-tip',
|
||||
'fadeIn' : 50,
|
||||
'fadeOut' : 50,
|
||||
'delay' : 200
|
||||
});
|
||||
|
||||
// wc_input_table tables
|
||||
jQuery('.wc_input_table.sortable tbody').sortable({
|
||||
|
@ -101,7 +98,7 @@ jQuery(function(){
|
|||
jQuery('.wc_input_table').on( 'focus click', 'input', function( e ) {
|
||||
|
||||
$this_table = jQuery(this).closest('table');
|
||||
$this_row = jQuery(this).closest('tr');
|
||||
$this_row = jQuery(this).closest('tr');
|
||||
|
||||
if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && jQuery(this).is(':focus') ) ) {
|
||||
|
||||
|
@ -144,7 +141,7 @@ jQuery(function(){
|
|||
jQuery( '.woocommerce_page_wc-settings .shippingrows tbody tr:even' ).addClass( 'alternate' );
|
||||
|
||||
// Availability inputs
|
||||
jQuery('select.availability').change(function(){
|
||||
jQuery('select.availability').change(function(){
|
||||
if ( jQuery(this).val() == "all" ) {
|
||||
jQuery(this).closest('tr').next('tr').hide();
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue