From 7e79f4867ec072c6a67a8838b832ef0164e17f6d Mon Sep 17 00:00:00 2001 From: Nat Hamilton Date: Wed, 28 Nov 2018 13:10:27 -0600 Subject: [PATCH] fix(addresscapture): stop invalid address being submitted --- .../AddressCapture/v1/AddressCapture.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/package/src/components/AddressCapture/v1/AddressCapture.js b/package/src/components/AddressCapture/v1/AddressCapture.js index b79ad242d..0f7818fa8 100644 --- a/package/src/components/AddressCapture/v1/AddressCapture.js +++ b/package/src/components/AddressCapture/v1/AddressCapture.js @@ -18,6 +18,21 @@ class AddressCapture extends Component { * Place holder for Address Name field. */ addressNamePlaceholder: PropTypes.string, + /** + * Errors array + */ + errors: PropTypes.arrayOf( + PropTypes.shape({ + /** + * Error message + */ + message: PropTypes.string.isRequired, + /** + * Error name + */ + name: PropTypes.string.isRequired + }) + ), /** * OnChange event callback */ @@ -47,6 +62,10 @@ class AddressCapture extends Component { * Address validations address suggestion */ addressSuggestion: CustomPropTypes.address, + /** + * Address validation error object + */ + validationError: PropTypes.object, /** * The selected address option */ @@ -127,6 +146,17 @@ class AddressCapture extends Component { return !!addressSuggestion; } + /** + * + * @method hasValidationError + * @summary returns true if we have any validation errors from a address validation service + * @return {Boolean} - true if validation errors on props + */ + get hasValidationError() { + const { addressReviewProps: { validationError } } = this.props; + return !!validationError; + } + /** * * @method addressEntered @@ -235,7 +265,7 @@ class AddressCapture extends Component { const { onAddressValidation, onSubmit } = this.props; if (onAddressValidation && !address.isValid) { await onAddressValidation(address); - if (!this.hasAddressSuggestion) await onSubmit(address); + if (!this.hasAddressSuggestion && !this.hasValidationError) await onSubmit(address); } else { await onSubmit(address); }