From b8c26f18f8b1ed141c17cf1574693b86cbeeadc3 Mon Sep 17 00:00:00 2001 From: Alexandre Segura Date: Tue, 1 Sep 2020 16:54:15 +0200 Subject: [PATCH] Use form validation for address picker. See #1574. --- js/app/cart/components/Cart.js | 3 ++- js/app/forms/delivery.js | 18 +++--------------- js/app/restaurant/index.js | 11 +++++++++++ js/app/utils/address.js | 25 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 js/app/utils/address.js diff --git a/js/app/cart/components/Cart.js b/js/app/cart/components/Cart.js index 168302bd93..7d964da1f3 100644 --- a/js/app/cart/components/Cart.js +++ b/js/app/cart/components/Cart.js @@ -45,7 +45,8 @@ class Cart extends Component { geohash={ '' } key={ this.props.streetAddress } onAddressSelected={ (value, address) => this.props.changeAddress(address) } - disabled={ this.props.isCollectionOnly || this.props.takeaway } /> + disabled={ this.props.isCollectionOnly || this.props.takeaway } + required /> { this.props.isCollectionEnabled && (
{ + + if (!searchInput.validity.valid) { + return + } + + const isValidLatLng = !_.isEmpty(latInput.value) && !_.isEmpty(lngInput.value) + const isStreetAddressTouched = searchInput.value !== streetAddrInput.value + + if (isStreetAddressTouched || !isValidLatLng) { + e.preventDefault(); + + searchInput.setCustomValidity(i18n.t('PLEASE_SELECT_ADDRESS')) + if (HTMLInputElement.prototype.reportValidity) { + searchInput.reportValidity() + } + + return false + } + + return true +}