Skip to content

Commit 9aa87ec

Browse files
committed
Update input handler
1 parent 18858a7 commit 9aa87ec

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/MglGeocoderControl.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
8282
data() {
8383
return {
84-
control: null
84+
control: null,
85+
initial: true
8586
}
8687
},
8788
@@ -105,6 +106,11 @@
105106
if (this.accessToken) this.mapbox.accessToken = this.accessToken
106107
const Geocoder = this.mapboxGeocoder
107108
this.control = new Geocoder(this._props)
109+
this.control.on('results', this.$_updateInput)
110+
},
111+
112+
beforeDestroy() {
113+
this.control.off('results', this.$_updateInput)
108114
},
109115
110116
methods: {
@@ -124,6 +130,14 @@
124130
this.$_bindSelfEvents(eventsToListen, this.control)
125131
}
126132
payload.component.$off('load', this.$_deferredMount)
133+
this.initial = false
134+
},
135+
136+
$_updateInput(results) {
137+
if (!this.initial) {
138+
const input = results.query ? results.query.join('') : ''
139+
this.$emit('update:input', input)
140+
}
127141
},
128142
129143
query(query) {

0 commit comments

Comments
 (0)