Skip to content

Commit a3efa33

Browse files
committed
Hidden Lat/Lng/Address fields are cleared when the search address field is empty
1 parent 77c873d commit a3efa33

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

SimpleMapPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function getDescription()
2424

2525
public function getVersion()
2626
{
27-
return '1.0.0';
27+
return '1.0.1';
2828
}
2929

3030
public function getDeveloper()

resources/SimpleMap_Map.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ SimpleMap.prototype.loadMaps = function () {
8181
// Setup Map
8282
SimpleMap.prototype.setupMap = function () {
8383
this.setup = true;
84+
var self = this;
8485

8586
// Geocoder (for address search)
8687
this.geocoder = new google.maps.Geocoder();
@@ -100,6 +101,10 @@ SimpleMap.prototype.setupMap = function () {
100101
autocomplete.map = this.map;
101102
autocomplete.bindTo('bounds', this.map);
102103

104+
this.address.addEventListener('input', function () {
105+
if (this.value === '') self.clear();
106+
});
107+
103108
// Add marker
104109
this.map.marker = new google.maps.Marker({
105110
draggable: true,
@@ -114,8 +119,6 @@ SimpleMap.prototype.setupMap = function () {
114119
// Update the marker location & center the map
115120
this.update(lat, lng, false, true).center();
116121

117-
var self = this;
118-
119122
// When the autocomplete place changes
120123
google.maps.event.addListener(autocomplete, 'place_changed', function () {
121124
var address = self.address.value, lat, lng;
@@ -226,10 +229,9 @@ SimpleMap.prototype.geo = function (latLng, callback) {
226229
};
227230

228231
SimpleMap.prototype.clear = function () {
229-
self.address.value = '';
230-
self.inputs.lat.value = '';
231-
self.inputs.lng.value = '';
232-
self.inputs.address.value = '';
232+
this.inputs.lat.value = '';
233+
this.inputs.lng.value = '';
234+
this.inputs.address.value = '';
233235
};
234236

235237
window.SimpleMap = SimpleMap;

0 commit comments

Comments
 (0)