smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.03k stars 273 forks source link

Adding option to stop propagation and add autocomplete=none to search form #152

Closed hubnerd closed 4 years ago

hubnerd commented 6 years ago

Hi,

I have added an option "stopClickPropagation" to stop propagation on click to allow people to be able to use something like map.on('click', function() { alert("Click") }); and not have it trigger on clicking the search form.

I have also added autocomplete="none" to the search form due to web browsers trying to autocomplete and hiding the search results.

Not sure if you want these commits but I thought I would chuck them your way :)

smeijer commented 6 years ago

Good idea, thanks for the PR. Although I do think it's better to use e.preventDefault instead. I don't like blocking propagations.

Step 1 is call e.preventDefault in the button click of leaflet-geosearch. Step 2 is for the user, to check if his click is not prevented higher on the chain, with e.isDefaultPrevented.

Can you adjust this PR accordingly?

hubnerd commented 6 years ago

Sorry for the time this took, not had a minute to myself lately. Build is clean but the build fails due to googleprovider test

Azmisov commented 6 years ago

Personally, I would prefer just using stopPropagation. If you really want to let user's listen to the control's click events higher up, why don't we just make it configurable? Just have a stopPropagation option (true/false) that registers the form click event. Otherwise, it will bubble up like normal. Straightforward, and they don't have to check e.originalEvent.defaultPrevented in every single other event handler they've registered on the map.

smeijer commented 6 years ago

Fair enough. I'm in for @Azmisov's suggestion. Could someone adjust this PR to add a stopPropagation option which defaults to true?

smeijer commented 4 years ago

leaflet-geosearch v3 has been released, and embeds this fix.

Thanks for your contribution.