$.trim is not a function error with jQuery 4.x — form validation broken
-
Description
The withdrawal form is completely broken when WordPress loads jQuery 4.x. Submitting the form throws a
JavaScript error that prevents any validation from running.Error
Uncaught TypeError: $.trim is not a function
at validateForm (wbte-ewb-frontend.js?ver=1.0.2:238:13)
at HTMLFormElement. (wbte-ewb-frontend.js?ver=1.0.2:455:11)Root cause
jQuery.trim() was removed in jQuery 4.0.0 (it was deprecated since jQuery 3.3.0). The file
assets/js/wbte-ewb-frontend.js calls $.trim() on three separate lines:- Line 238: $.trim( $( ‘#wbte_ewb_order_number’ ).val() )
- Line 241: $.trim( $( ‘#wbte_ewb_guest_email’ ).val() )
- Line 259: $.trim( $( ‘#wbte_ewb_reason’ ).val() ) Expected behavior The withdrawal form validates and submits correctly regardless of the jQuery version loaded. Fix Replace all $.trim( value ) calls with the native value.trim():
- if ( ! $.trim( $( ‘#wbte_ewb_order_number’ ).val() ) ) {
- if ( ! $( ‘#wbte_ewb_order_number’ ).val().trim() ) {
- if ( ! $.trim( $( ‘#wbte_ewb_guest_email’ ).val() ) ) {
- if ( ! $( ‘#wbte_ewb_guest_email’ ).val().trim() ) {
- if ( params.reason_required === ‘yes’ && ! $.trim( $( ‘#wbte_ewb_reason’ ).val() ) ) {
- if ( params.reason_required === ‘yes’ && ! $( ‘#wbte_ewb_reason’ ).val().trim() ) { Environment
- jQuery: 4.0.0
- Plugin version: 1.0.2
- WordPress: tested up to 7.0 (as stated in plugin header)
- WooCommerce: tested up to 10.8.1 (as stated in plugin header)
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.