From 00dda9769d549266b75c7442ad0412dad50badf6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 25 Apr 2018 16:21:07 +0300 Subject: [PATCH] Improve postal code lookup --- resources/views/clients/edit.blade.php | 4 ++-- resources/views/partials/google_geocode.blade.php | 7 +++++-- resources/views/vendors/edit.blade.php | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/resources/views/clients/edit.blade.php b/resources/views/clients/edit.blade.php index 5101654571..e19db32394 100644 --- a/resources/views/clients/edit.blade.php +++ b/resources/views/clients/edit.blade.php @@ -94,7 +94,7 @@ {!! Former::text('city') !!} {!! Former::text('state') !!} {!! Former::text('postal_code') - ->onchange(config('ninja.google_maps_enabled') ? 'lookupPostalCode()' : '') !!} + ->oninput(config('ninja.google_maps_enabled') ? 'lookupPostalCode()' : '') !!} {!! Former::select('country_id')->addOption('','') ->fromQuery($countries, 'name', 'id') !!} @@ -112,7 +112,7 @@ {!! Former::text('shipping_city')->label('city') !!} {!! Former::text('shipping_state')->label('state') !!} {!! Former::text('shipping_postal_code') - ->onchange(config('ninja.google_maps_enabled') ? 'lookupPostalCode(true)' : '') + ->oninput(config('ninja.google_maps_enabled') ? 'lookupPostalCode(true)' : '') ->label('postal_code') !!} {!! Former::select('shipping_country_id')->addOption('','') ->fromQuery($countries, 'name', 'id')->label('country_id') !!} diff --git a/resources/views/partials/google_geocode.blade.php b/resources/views/partials/google_geocode.blade.php index 8af6593900..bcf41e175a 100644 --- a/resources/views/partials/google_geocode.blade.php +++ b/resources/views/partials/google_geocode.blade.php @@ -64,10 +64,12 @@ function lookupPostalCode(isShipping) { var countryId = $('#' + countryField).val() || {{ $account->getCountryId() }}; var countryCode = countryMap[countryId].iso_3166_2; - if (! postalCode) { + if (! postalCode || postalCode.length < 5) { return; } + $('#' + cityField).attr('placeholder', {!! json_encode(trans('texts.loading') . '...') !!}); + var geocoder = new google.maps.Geocoder; geocoder.geocode({ componentRestrictions: { @@ -97,8 +99,9 @@ function lookupPostalCode(isShipping) { } } } + $('#' + cityField).attr('placeholder', ''); } else { - $('#' + cityField).attr("placeholder", {!! json_encode(trans('texts.no_match_found')) !!}); + $('#' + cityField).attr('placeholder', {!! json_encode(trans('texts.no_match_found')) !!}); } showGeocodePlaceholder(isShipping); }); diff --git a/resources/views/vendors/edit.blade.php b/resources/views/vendors/edit.blade.php index 743a4562bd..d0cc6d73ab 100644 --- a/resources/views/vendors/edit.blade.php +++ b/resources/views/vendors/edit.blade.php @@ -65,7 +65,7 @@ {!! Former::text('state') !!} {!! Former::text('postal_code') - ->onchange(config('ninja.google_maps_enabled') ? 'lookupPostalCode()' : '') !!} + ->oninput(config('ninja.google_maps_enabled') ? 'lookupPostalCode()' : '') !!} {!! Former::select('country_id')->addOption('','') ->fromQuery($countries, 'name', 'id') !!}