From d37f1918338babb900641a05203568a1512c252a Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 16 May 2016 17:04:38 -0500 Subject: [PATCH] Add decimal error and fix for refund amount --- assets/js/admin/woocommerce_admin.js | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index 9059a6219ce..9b3b1d806d1 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -109,6 +109,47 @@ jQuery( function ( $ ) { } }) + .on( 'change', '.wc-order-totals #refund_amount[type=text]', function() { + var regex; + + if ( $( this ).is( '#refund_amount' ) ) { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' ); + } else { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' ); + } + + var value = $( this ).val(); + var newvalue = value.replace( regex, '' ); + + if ( value !== newvalue ) { + $( this ).val( newvalue ); + } + }) + + .on( 'keyup', '.wc-order-totals #refund_amount[type=text]', function() { + var regex, error; + + if ( $( this ).is( '#refund_amount' ) ) { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' ); + error = 'i18n_mon_decimal_error'; + } else if ( $( this ).is( '.wc_input_country_iso' ) ) { + regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' ); + error = 'i18n_country_iso_error'; + } else { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' ); + error = 'i18n_decimal_error'; + } + + var value = $( this ).val(); + var newvalue = value.replace( regex, '' ); + + if ( value !== newvalue ) { + $( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), error ] ); + } else { + $( document.body ).triggerHandler( 'wc_remove_error_tip', [ $( this ), error ] ); + } + }) + .on( 'init_tooltips', function() { var tiptip_args = { 'attribute': 'data-tip',