Skip to content

Commit 82da838

Browse files
quinnchrperliedman
authored andcommitted
Enable customization of geocoder result HTML (#484)
* Adding geocoderResult option to enable customization of geocoder result html * Changing option name for geocoderResult
1 parent 163c00e commit 82da838

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/autocomplete.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@
7474
tr = L.DomUtil.create('tr', '', this._resultTable);
7575
tr.setAttribute('data-result-index', i);
7676
td = L.DomUtil.create('td', '', tr);
77-
text = document.createTextNode(results[i].name);
77+
78+
if (this.options.formatGeocoderResult) {
79+
text = this.options.formatGeocoderResult(results[i]);
80+
} else {
81+
text = document.createTextNode(results[i].name);
82+
}
83+
7884
td.appendChild(text);
7985
// mousedown + click because:
8086
// http://stackoverflow.com/questions/10652852/jquery-fire-click-before-blur-event

src/geocoder-element.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
}, this);
8686
}
8787

88+
if (typeof this.options.formatGeocoderResult == 'function') {
89+
this.options.autocompleteOptions.formatGeocoderResult = this.options.formatGeocoderResult;
90+
}
91+
8892
new Autocomplete(geocoderInput, function(r) {
8993
geocoderInput.value = r.name;
9094
wp.name = r.name;

0 commit comments

Comments
 (0)