Skip to content

Commit

Permalink
Handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
imranhsayed committed May 8, 2021
1 parent c9ee285 commit 3446ab8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/components/checkout/CheckoutForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ const CheckoutForm = ({countriesData}) => {
const handleFormSubmit = (event) => {
event.preventDefault();

// Validate Billing and Shipping Details
const billingValidationResult = validateAndSanitizeCheckoutForm(input?.billing);
/**
* Validate Billing and Shipping Details
*
* Note: If billing is different than shipping address, only then validate billing.
*/
const billingValidationResult = input?.billingDifferentThanShipping ? validateAndSanitizeCheckoutForm(input?.billing) : {errors: null, isValid: true};
const shippingValidationResult = validateAndSanitizeCheckoutForm(input?.shipping);

if (!shippingValidationResult.isValid || !billingValidationResult.isValid) {
Expand Down
2 changes: 1 addition & 1 deletion src/validator/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const validateAndSanitizeCheckoutForm = ( data ) => {
}

if ( required && validator.isEmpty( data[ fieldName ] ) ) {
errors[ fieldName ] = `${errorContent} is requireds`;
errors[ fieldName ] = `${errorContent} is required`;
}


Expand Down

0 comments on commit 3446ab8

Please sign in to comment.