mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Add fields to the basic js validation error message
This commit is contained in:
parent
d9a6a89f2c
commit
88838ce5ca
2 changed files with 21 additions and 2 deletions
|
@ -38,9 +38,22 @@ const bootstrap = () => {
|
|||
requiredFields.each((i, input) => {
|
||||
jQuery(input).trigger('validate');
|
||||
});
|
||||
if (jQuery('form.woocommerce-checkout .validate-required.woocommerce-invalid:visible').length) {
|
||||
const invalidFields = Array.from(jQuery('form.woocommerce-checkout .validate-required.woocommerce-invalid:visible'));
|
||||
if (invalidFields.length) {
|
||||
const namesMap = PayPalCommerceGateway.labels.elements;
|
||||
const labels = invalidFields.map(el => {
|
||||
const name = el.querySelector('[name]')?.getAttribute('name');
|
||||
if (name && name in namesMap) {
|
||||
return namesMap[name];
|
||||
}
|
||||
return el.querySelector('label').textContent
|
||||
.replaceAll('*', '')
|
||||
.trim();
|
||||
}).filter(s => s.length > 2);
|
||||
|
||||
errorHandler.clear();
|
||||
errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
|
||||
labels.forEach(s => errorHandler.message(s)); // each message() call adds <li>
|
||||
|
||||
return actions.reject();
|
||||
}
|
||||
|
|
|
@ -852,7 +852,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
'messages' => $this->message_values(),
|
||||
'labels' => array(
|
||||
'error' => array(
|
||||
'error' => array(
|
||||
'generic' => __(
|
||||
'Something went wrong. Please try again or choose another payment source.',
|
||||
'woocommerce-paypal-payments'
|
||||
|
@ -862,6 +862,12 @@ class SmartButton implements SmartButtonInterface {
|
|||
'woocommerce-paypal-payments'
|
||||
),
|
||||
),
|
||||
'elements' => array( // Map <form element name> => text, used for error messages.
|
||||
'terms' => __(
|
||||
'Terms and conditions',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
),
|
||||
),
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue