Skip to content

Commit

Permalink
fix(addresscapture): stop invalid address being submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnnat committed Nov 28, 2018
1 parent a6d1b89 commit 7e79f48
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion package/src/components/AddressCapture/v1/AddressCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 7e79f48

Please sign in to comment.