Merge pull request #5573 from claudiosmweb/5180-tax-validation
Add validation for country code in tax settings
This commit is contained in:
commit
3fbd036b81
|
@ -1,13 +1,15 @@
|
|||
/* global woocommerce_admin */
|
||||
|
||||
/**
|
||||
* WooCommerce Admin JS
|
||||
*/
|
||||
jQuery(function(){
|
||||
|
||||
// Price input validation
|
||||
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('body').on( 'blur', '.wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]', function() {
|
||||
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
|
||||
return this;
|
||||
});
|
||||
|
||||
jQuery('body').on('keyup change', '.wc_input_price[type=text]', function(){
|
||||
var value = jQuery(this).val();
|
||||
|
@ -47,6 +49,24 @@ jQuery(function(){
|
|||
return this;
|
||||
});
|
||||
|
||||
jQuery('body').on('keyup change', '.wc_input_country_iso[type=text]', function(){
|
||||
var value = jQuery(this).val();
|
||||
var regex = new RegExp( '^([A-Z])?([A-Z])$' );
|
||||
|
||||
if ( ! regex.test( value ) ) {
|
||||
jQuery(this).val( '' );
|
||||
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_country_iso_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(){
|
||||
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
|
||||
});
|
||||
|
@ -195,4 +215,4 @@ jQuery(function(){
|
|||
// Attribute term table
|
||||
jQuery( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );
|
||||
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -107,6 +107,7 @@ class WC_Admin_Assets {
|
|||
$params = array(
|
||||
'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
|
||||
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), get_option( 'woocommerce_price_decimal_sep' ) ),
|
||||
'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
|
||||
'decimal_point' => $decimal,
|
||||
'mon_decimal_point' => get_option( 'woocommerce_price_decimal_sep' )
|
||||
);
|
||||
|
|
|
@ -310,7 +310,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
|
||||
|
||||
<td class="country" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" class="wc_input_country_iso" />
|
||||
</td>
|
||||
|
||||
<td class="state" width="8%">
|
||||
|
@ -420,7 +420,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
var code = '<tr class="new">\
|
||||
<td class="sort"> </td>\
|
||||
<td class="country" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
|
||||
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" class="wc_input_country_iso" />\
|
||||
</td>\
|
||||
<td class="state" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
|
||||
|
|
Loading…
Reference in New Issue