Skip to content

feat: added realtime client side validation on checkout form inputs#27

Open
Ankesh2004 wants to merge 1 commit intojuspay:mainfrom
Ankesh2004:add-client-side-validation
Open

feat: added realtime client side validation on checkout form inputs#27
Ankesh2004 wants to merge 1 commit intojuspay:mainfrom
Ankesh2004:add-client-side-validation

Conversation

@Ankesh2004
Copy link
Copy Markdown

Type of Change

  • Enhancement

Description

Adds realtime input validations on checkout page.

Additional Changes

  • Creates checkout-validation.js in js folder.
  • Adds above script in hyperswitch-checkout.php

Motivation and Context

Fixes issue juspay/hyperswitch#6169

How did you test it?

Locally tested
image

@sakksham7
Copy link
Copy Markdown

Hey @Ankesh2004 can you please add a screen recording of how validations will work covering all edge cases along with the screenshot you have provided.

@gorakhnathy7
Copy link
Copy Markdown

Hey @Ankesh2004 Any updates.

);
}
}
add_action('wp_enqueue_scripts', 'enqueue_checkout_validation_script');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_action('wp_enqueue_scripts', 'enqueue_checkout_validation_script');
add_action( 'wp_enqueue_scripts', 'enqueue_checkout_validation_script' );

console.error('Place Order button not found');
return;
}
console.log('Place Order button found');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('Place Order button found');

Comment on lines +5 to +14
if (!form) {
console.error('Checkout form not found');
return;
}
console.log('Checkout form found');

if (!placeOrderButton) {
console.error('Place Order button not found');
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!form) {
console.error('Checkout form not found');
return;
}
console.log('Checkout form found');
if (!placeOrderButton) {
console.error('Place Order button not found');
return;
}

Comment on lines +26 to +29
if (!emailField || !firstNameField || !lastNameField || !zipCodeField || !phoneField) {
console.error('One or more form fields not found');
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!emailField || !firstNameField || !lastNameField || !zipCodeField || !phoneField) {
console.error('One or more form fields not found');
return;
}

@vsrivatsa-edinburgh
Copy link
Copy Markdown
Contributor

This is good work
I'm wondering how to solve this without using hardcoded error messages. Does WC expose any functions on their scripts that can be used to spit out respective error messages - that way you wouldn't have to worry about error messages in other languages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants