Replace jQuery.change()

This commit is contained in:
Kathy Daring 2021-01-07 15:08:36 -07:00
parent adb2c6b86e
commit 60f49f25d0
15 changed files with 65 additions and 65 deletions

View File

@ -12,7 +12,7 @@ jQuery(function( $ ) {
init: function() {
$( 'select#discount_type' )
.on( 'change', this.type_options )
.change();
.trigger( 'change' );
this.insert_generate_coupon_code_button();
$( '.button.generate-coupon-code' ).on( 'click', this.generate_coupon_code );

View File

@ -90,7 +90,7 @@ jQuery( function ( $ ) {
$state.replaceWith( $newstate );
$newstate.show().selectWoo().hide().change();
$newstate.show().selectWoo().hide().trigger( 'change' );
} else {
$newstate = $( '<input type="text" />' )
.prop( 'id', input_id )
@ -143,8 +143,8 @@ jQuery( function ( $ ) {
$this.parent().find( 'a' ).toggle();
if ( ! $country_input.val() ) {
$country_input.val( woocommerce_admin_meta_boxes_order.default_country ).change();
$state_input.val( woocommerce_admin_meta_boxes_order.default_state ).change();
$country_input.val( woocommerce_admin_meta_boxes_order.default_country ).trigger( 'change' );
$state_input.val( woocommerce_admin_meta_boxes_order.default_state ).trigger( 'change' );
}
$edit_address.show();
@ -196,7 +196,7 @@ jQuery( function ( $ ) {
success: function( response ) {
if ( response && response.billing ) {
$.each( response.billing, function( key, data ) {
$( ':input#_billing_' + key ).val( data ).change();
$( ':input#_billing_' + key ).val( data ).trigger( 'change' );
});
}
$( 'div.edit_address' ).unblock();
@ -238,7 +238,7 @@ jQuery( function ( $ ) {
success: function( response ) {
if ( response && response.billing ) {
$.each( response.shipping, function( key, data ) {
$( ':input#_shipping_' + key ).val( data ).change();
$( ':input#_shipping_' + key ).val( data ).trigger( 'change' );
});
}
$( 'div.edit_address' ).unblock();
@ -253,7 +253,7 @@ jQuery( function ( $ ) {
$('.order_data_column :input[name^="_billing_"]').each( function() {
var input_name = $(this).attr('name');
input_name = input_name.replace( '_billing_', '_shipping_' );
$( ':input#' + input_name ).val( $(this).val() ).change();
$( ':input#' + input_name ).val( $(this).val() ).trigger( 'change' );
});
}
return false;
@ -1002,7 +1002,7 @@ jQuery( function ( $ ) {
'',
woocommerce_admin.mon_decimal_point
) )
.change();
.trigger( 'change' );
},
amount_changed: function() {
@ -1032,7 +1032,7 @@ jQuery( function ( $ ) {
parseFloat( accounting.formatNumber( unit_total * refund_qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
.toString()
.replace( '.', woocommerce_admin.mon_decimal_point )
).change();
).trigger( 'change' );
// Taxes
$( '.refund_line_tax', $row ).each( function() {
@ -1054,9 +1054,9 @@ jQuery( function ( $ ) {
parseFloat( accounting.formatNumber( unit_total_tax * refund_qty, precision, '' ) )
.toString()
.replace( '.', woocommerce_admin.mon_decimal_point )
).change();
).trigger( 'change' );
} else {
$refund_line_total_tax.val( 0 ).change();
$refund_line_total_tax.val( 0 ).trigger( 'change' );
}
});
@ -1401,7 +1401,7 @@ jQuery( function ( $ ) {
}
$( document.body ).trigger( 'wc-init-datepickers' );
$( '#grant_access_id' ).val( '' ).change();
$( '#grant_access_id' ).val( '' ).trigger( 'change' );
$( '.order_download_permissions' ).unblock();
});

View File

@ -19,7 +19,7 @@ jQuery( function( $ ) {
.on( 'click', 'h3 .sort', this.set_menu_order )
.on( 'reload', this.reload );
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).change();
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock' ).trigger( 'change' );
$( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', this.variations_loaded );
$( document.body ).on( 'woocommerce_variations_added', this.variation_added );
},
@ -95,7 +95,7 @@ jQuery( function( $ ) {
if ( ! needsUpdate ) {
// Show/hide downloadable, virtual and stock fields
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock', wrapper ).change();
$( 'input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock', wrapper ).trigger( 'change' );
// Open sale schedule fields when have some sale price date
$( '.woocommerce_variation', wrapper ).each( function( index, el ) {
@ -138,7 +138,7 @@ jQuery( function( $ ) {
date = $( this ).datepicker( 'getDate' );
dates.not( this ).datepicker( 'option', option, date );
$( this ).change();
$( this ).trigger( 'change' );
}
});
@ -182,7 +182,7 @@ jQuery( function( $ ) {
if ( value != null ) {
// Set value, save changes and reload view
$menu_order.val( parseInt( value, 10 ) ).change();
$menu_order.val( parseInt( value, 10 ) ).trigger( 'change' );
wc_meta_boxes_product_variations_ajax.save_variations();
}
},
@ -199,7 +199,7 @@ jQuery( function( $ ) {
$( '.variation_menu_order', el )
.val( parseInt( $( el )
.index( '.woocommerce_variations .woocommerce_variation' ), 10 ) + 1 + offset )
.change();
.trigger( 'change' );
});
}
};
@ -262,7 +262,7 @@ jQuery( function( $ ) {
if ( $button.is( '.remove' ) ) {
$( '.upload_image_id', wc_meta_boxes_product_variations_media.setting_variation_image ).val( '' ).change();
$( '.upload_image_id', wc_meta_boxes_product_variations_media.setting_variation_image ).val( '' ).trigger( 'change' );
wc_meta_boxes_product_variations_media.setting_variation_image.find( 'img' ).eq( 0 )
.attr( 'src', woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src );
wc_meta_boxes_product_variations_media.setting_variation_image.find( '.upload_image_button' ).removeClass( 'remove' );
@ -301,7 +301,7 @@ jQuery( function( $ ) {
.get( 'selection' ).first().toJSON(),
url = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url;
$( '.upload_image_id', wc_meta_boxes_product_variations_media.setting_variation_image ).val( attachment.id ).change();
$( '.upload_image_id', wc_meta_boxes_product_variations_media.setting_variation_image ).val( attachment.id ).trigger( 'change' );
wc_meta_boxes_product_variations_media.setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' );
wc_meta_boxes_product_variations_media.setting_variation_image.find( 'img' ).eq( 0 ).attr( 'src', url );
@ -977,7 +977,7 @@ jQuery( function( $ ) {
* Set page
*/
set_page: function( page ) {
$( '.variations-pagenav .page-selector' ).val( page ).first().change();
$( '.variations-pagenav .page-selector' ).val( page ).first().trigger( 'change' );
},
/**

View File

@ -100,7 +100,7 @@ jQuery( function( $ ) {
var select_val = $( this ).val();
if ( 'variable' === select_val ) {
$( 'input#_manage_stock' ).change();
$( 'input#_manage_stock' ).trigger( 'change' );
$( 'input#_downloadable' ).prop( 'checked', false );
$( 'input#_virtual' ).removeAttr( 'checked' );
} else if ( 'grouped' === select_val ) {
@ -117,7 +117,7 @@ jQuery( function( $ ) {
$( document.body ).trigger( 'woocommerce-product-type-change', select_val, $( this ) );
}).change();
}).trigger( 'change' );
$( 'input#_downloadable, input#_virtual' ).change( function() {
show_and_hide_panels();
@ -165,7 +165,7 @@ jQuery( function( $ ) {
$( '.hide_if_' + product_type ).hide();
$( 'input#_manage_stock' ).change();
$( 'input#_manage_stock' ).trigger( 'change' );
// Hide empty panels/tabs after display.
$( '.woocommerce_options_panel' ).each( function() {
@ -250,8 +250,8 @@ jQuery( function( $ ) {
$( 'p.stock_status_field:not( .hide_if_' + product_type + ' )' ).show();
}
$( 'input.variable_manage_stock' ).change();
}).change();
$( 'input.variable_manage_stock' ).trigger( 'change' );
}).trigger( 'change' );
// Date picker fields.
function date_picker_select( datepicker ) {
@ -260,7 +260,7 @@ jQuery( function( $ ) {
date = $( datepicker ).datepicker( 'getDate' );
$( otherDateField ).datepicker( 'option', option, date );
$( datepicker ).change();
$( datepicker ).trigger( 'change' );
}
$( '.sale_price_dates_fields' ).each( function() {
@ -356,13 +356,13 @@ jQuery( function( $ ) {
$( '.product_attributes' ).on( 'click', 'button.select_all_attributes', function() {
$( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' );
$( this ).closest( 'td' ).find( 'select' ).change();
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
return false;
});
$( '.product_attributes' ).on( 'click', 'button.select_no_attributes', function() {
$( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' );
$( this ).closest( 'td' ).find( 'select' ).change();
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
return false;
});
@ -436,7 +436,7 @@ jQuery( function( $ ) {
// Success.
$wrapper.find( 'select.attribute_values' )
.append( '<option value="' + response.term_id + '" selected="selected">' + response.name + '</option>' );
$wrapper.find( 'select.attribute_values' ).change();
$wrapper.find( 'select.attribute_values' ).trigger( 'change' );
}
$( '.product_attributes' ).unblock();
@ -556,7 +556,7 @@ jQuery( function( $ ) {
}
});
file_path_field.val( file_path ).change();
file_path_field.val( file_path ).trigger( 'change' );
});
// Set post to 0 and set our custom type.

View File

@ -44,8 +44,8 @@ jQuery(
$( 'input[name="_width"]', '.inline-edit-row' ).val( width );
$( 'input[name="_height"]', '.inline-edit-row' ).val( height );
$( 'select[name="_shipping_class"] option:selected', '.inline-edit-row' ).attr( 'selected', false ).change();
$( 'select[name="_shipping_class"] option[value="' + shipping_class + '"]' ).attr( 'selected', 'selected' ).change();
$( 'select[name="_shipping_class"] option:selected', '.inline-edit-row' ).attr( 'selected', false ).trigger( 'change' );
$( 'select[name="_shipping_class"] option[value="' + shipping_class + '"]' ).attr( 'selected', 'selected' ).trigger( 'change' );
$( 'input[name="_stock"]', '.inline-edit-row' ).val( stock );
$( 'input[name="menu_order"]', '.inline-edit-row' ).val( menu_order );

View File

@ -13,7 +13,7 @@
$( this ).closest('tr').next( 'tr' ).hide();
$( this ).closest('tr').next().next( 'tr' ).hide();
}
}).change();
}).trigger( 'change' );
// Ship Countries
$( 'select#woocommerce_ship_to_countries' ).change( function() {
@ -22,7 +22,7 @@
} else {
$( this ).closest('tr').next( 'tr' ).hide();
}
}).change();
}).trigger( 'change' );
// Stock management
$( 'input#woocommerce_manage_stock' ).change( function() {
@ -31,7 +31,7 @@
} else {
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).hide();
}
}).change();
}).trigger( 'change' );
// Color picker
$( '.colorpick' )
@ -56,9 +56,9 @@
var original_value = $( this ).data( 'original-value' );
if ( original_value.match( /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ ) ) {
$( this ).val( $( this ).data( 'original-value' ) ).change();
$( this ).val( $( this ).data( 'original-value' ) ).trigger( 'change' );
} else {
$( this ).val( '' ).change();
$( this ).val( '' ).trigger( 'change' );
}
}
});

View File

@ -71,7 +71,7 @@ jQuery( function ( $ ) {
$state.replaceWith( $newstate );
$newstate.show().selectWoo().hide().change();
$newstate.show().selectWoo().hide().trigger( 'change' );
} else {
$newstate = $( '<input type="text" />' )
.prop( 'id', input_id )

View File

@ -93,7 +93,7 @@
if ( -1 !== $.inArray( 'variation', $( this ).val() ) ) {
exportCategory.closest( 'tr' ).hide();
exportCategory.val( '' ).change(); // Reset WooSelect selected value.
exportCategory.val( '' ).trigger( 'change' ); // Reset WooSelect selected value.
} else {
exportCategory.closest( 'tr' ).show();
}

View File

@ -72,13 +72,13 @@ jQuery( function( $ ) {
} );
$( '.store-state-container' ).show();
$state_select.selectWoo().val( wc_base_state ).change().prop( 'required', true );
$state_select.selectWoo().val( wc_base_state ).trigger( 'change' ).prop( 'required', true );
} else {
$( '.store-state-container' ).hide();
$state_select.empty().val( '' ).change().prop( 'required', false );
$state_select.empty().val( '' ).trigger( 'change' ).prop( 'required', false );
}
$( '#currency_code' ).val( wc_setup_currencies[ country ] ).change();
$( '#currency_code' ).val( wc_setup_currencies[ country ] ).trigger( 'change' );
} );
/* Setup postcode field and validations */
@ -100,7 +100,7 @@ jQuery( function( $ ) {
}
} );
$( '#store_country' ).change();
$( '#store_country' ).trigger( 'change' );
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-service-enable input', function() {
if ( $( this ).is( ':checked' ) ) {
@ -135,7 +135,7 @@ jQuery( function( $ ) {
var $checkbox = $( this ).find( 'input[type="checkbox"]' );
$checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).change();
$checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).trigger( 'change' );
} );
$( '.wc-wizard-services-list-toggle' ).on( 'click', function() {
@ -165,7 +165,7 @@ jQuery( function( $ ) {
.removeClass( 'hide' )
.find( '.shipping-method-required-field' )
.prop( 'required', $checkbox.prop( 'checked' ) );
} ).find( '.wc-wizard-shipping-method-select .method' ).change();
} ).find( '.wc-wizard-shipping-method-select .method' ).trigger( 'change' );
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-enable', function() {
var checked = $( this ).is( ':checked' );
@ -239,7 +239,7 @@ jQuery( function( $ ) {
.prop( 'disabled', true )
.prop( 'required', false );
}
} ).find( 'input#stripe_create_account, input#ppec_paypal_reroute_requests' ).change();
} ).find( 'input#stripe_create_account, input#ppec_paypal_reroute_requests' ).trigger( 'change' );
function addPlugins( bySlug, $el, hover ) {
var plugins = $el.data( 'plugins' );

View File

@ -354,7 +354,7 @@
}
});
$( '.wc-shipping-zone-method-selector select' ).change();
$( '.wc-shipping-zone-method-selector select' ).trigger( 'change' );
},
onAddShippingMethodSubmitted: function( event, target, posted_data ) {
if ( 'wc-modal-add-shipping-method' === target ) {

View File

@ -315,7 +315,7 @@
} else {
$( this ).closest( 'tr' ).next( 'tr' ).show();
}
}).change();
}).trigger( 'change' );
// Hidden options
$( '.hide_options_if_checked' ).each( function() {
@ -331,7 +331,7 @@
.nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' )
.show();
}
}).change();
}).trigger( 'change' );
});
$( '.show_options_if_checked' ).each( function() {
@ -347,7 +347,7 @@
.nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' )
.hide();
}
}).change();
}).trigger( 'change' );
});
// Reviews.
@ -357,7 +357,7 @@
} else {
$( '#woocommerce_enable_review_rating' ).closest( 'tr' ).hide();
}
}).change();
}).trigger( 'change' );
// Attribute term table
$( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );

View File

@ -53,7 +53,7 @@
*/
VariationForm.prototype.onReset = function( event ) {
event.preventDefault();
event.data.variationForm.$attributeFields.val( '' ).change();
event.data.variationForm.$attributeFields.val( '' ).trigger( 'change' );
event.data.variationForm.$form.trigger( 'reset_data' );
};
@ -286,11 +286,11 @@
$template_html = $template_html.replace( '/*]]>*/', '' );
form.$singleVariation.html( $template_html );
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.variation_id ).change();
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.variation_id ).trigger( 'change' );
// Hide or show qty input
if ( variation.is_sold_individually === 'yes' ) {
$qty.find( 'input.qty' ).val( '1' ).attr( 'min', '1' ).attr( 'max', '' ).change();
$qty.find( 'input.qty' ).val( '1' ).attr( 'min', '1' ).attr( 'max', '' ).trigger( 'change' );
$qty.hide();
} else {
@ -304,7 +304,7 @@
qty_val = qty_val < parseFloat( variation.min_qty ) ? variation.min_qty : qty_val;
}
$qty_input.attr( 'min', variation.min_qty ).attr( 'max', variation.max_qty ).val( qty_val ).change();
$qty_input.attr( 'min', variation.min_qty ).attr( 'max', variation.max_qty ).val( qty_val ).trigger( 'change' );
$qty.show();
}
@ -327,7 +327,7 @@
VariationForm.prototype.onChange = function( event ) {
var form = event.data.variationForm;
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).change();
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).trigger( 'change' );
form.$form.find( '.wc-no-matching-variations' ).remove();
if ( form.useAjax ) {
@ -484,7 +484,7 @@
if ( selected_attr_val_valid ) {
current_attr_select.val( selected_attr_val );
} else {
current_attr_select.val( '' ).change();
current_attr_select.val( '' ).trigger( 'change' );
}
} else {
current_attr_select.val( '' ); // No change event to prevent infinite loop.

View File

@ -50,7 +50,7 @@ jQuery( function( $ ) {
this.$checkout_form.on( 'change', '#ship-to-different-address input', this.ship_to_different_address );
// Trigger events
this.$checkout_form.find( '#ship-to-different-address input' ).change();
this.$checkout_form.find( '#ship-to-different-address input' ).trigger( 'change' );
this.init_payment_methods();
// Update on page load
@ -58,7 +58,7 @@ jQuery( function( $ ) {
$( document.body ).trigger( 'init_checkout' );
}
if ( wc_checkout_params.option_guest_checkout === 'yes' ) {
$( 'input#createaccount' ).change( this.toggle_create_account ).change();
$( 'input#createaccount' ).change( this.toggle_create_account ).trigger( 'change' );
}
},
init_payment_methods: function() {
@ -130,7 +130,7 @@ jQuery( function( $ ) {
if ( $( this ).is( ':checked' ) ) {
// Ensure password is not pre-populated.
$( '#account_password' ).val( '' ).change();
$( '#account_password' ).val( '' ).trigger( 'change' );
$( 'div.create-account' ).slideDown();
}
},
@ -380,11 +380,11 @@ jQuery( function( $ ) {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
$( this ).prop( 'checked', paymentDetails[ ID ] ).change();
$( this ).prop( 'checked', paymentDetails[ ID ] ).trigger( 'change' );
} else if ( $.inArray( $( this ).attr( 'type' ), [ 'select' ] ) !== -1 ) {
$( this ).val( paymentDetails[ ID ] ).change();
$( this ).val( paymentDetails[ ID ] ).trigger( 'change' );
} else if ( null !== $( this ).val() && 0 === $( this ).val().length ) {
$( this ).val( paymentDetails[ ID ] ).change();
$( this ).val( paymentDetails[ ID ] ).trigger( 'change' );
}
}
});

View File

@ -142,7 +142,7 @@ jQuery( function( $ ) {
$statebox.append( $option );
} );
$statebox.val( value ).change();
$statebox.val( value ).trigger( 'change' );
$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );
}

View File

@ -17,7 +17,7 @@
'form.edit-account #password_1, form.lost_reset_password #password_1',
this.strengthMeter
);
$( 'form.checkout #createaccount' ).change();
$( 'form.checkout #createaccount' ).trigger( 'change' );
},
/**