From 78e076f0cbe226d056bf384c8cc87be531de706d Mon Sep 17 00:00:00 2001 From: Alex P Date: Fri, 18 Nov 2022 10:17:59 +0200 Subject: [PATCH] Trigger WC JS validation on button click to highlight empty fields --- modules/ppcp-button/resources/js/button.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index b2687e9d8..a118211a2 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -42,14 +42,17 @@ const bootstrap = () => { const onSmartButtonClick = (data, actions) => { window.ppcpFundingSource = data.fundingSource; + const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input'); + requiredFields.each((i, input) => { + jQuery(input).trigger('validate'); + }); if (PayPalCommerceGateway.basic_checkout_validation_enabled) { - // TODO: quick fix to get the error about empty form before attempting PayPal order - // it should solve #513 for most of the users, but proper solution should be implemented later. - const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input'); - requiredFields.each((i, input) => { - jQuery(input).trigger('validate'); - }); + // A quick fix to get the errors about empty form fields before attempting PayPal order, + // it should solve #513 for most of the users, but it is not a proper solution. + // Currently it is disabled by default because a better solution is now implemented + // (see woocommerce_paypal_payments_basic_checkout_validation_enabled, + // woocommerce_paypal_payments_early_wc_checkout_validation_enabled filters). const invalidFields = Array.from(jQuery('form.woocommerce-checkout .validate-required.woocommerce-invalid:visible')); if (invalidFields.length) { const billingFieldsContainer = document.querySelector('.woocommerce-billing-fields');