Problem/Motivation
I have a fairly niche use case that I've run into, in that the site design I'm working on calls for a location search in a mega menu and a location search on a directory page. By themselves they work fine, but since the module just uses the id of the option you chose to generate the lookup class name, if you load both of them at the same time it causes issues, because the location javascript only binds to one control. Drupal does support doing this in core, in that the form controls themselves all still have unique IDs, so I think it makes sense to support it here as well.
Proposed resolution
Instead of running the option_id though the uniqid function, first run it through Html::getUniqueId to ensure it's unique to the page, then feed that into the uniqid function. Also key the array entry into the clientLocation/geocoder arrays inside the locationInput array, so that they merge into one collection once the page loads and reads the drupalSettings. The attached patch does this and seems to work fine.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3163657-4.patch | 2.79 KB | uditrawat |
| #3 | geolocation_support-multiple-controls-on-the-same-page-2.patch | 2.79 KB | studgate |
| geolocation_support-multiple-controls-on-the-same-page.patch | 2.77 KB | jacobbell84 |
Comments
Comment #2
jacobbell84 commentedComment #3
studgate commentedUpdates to the patch for the latest version
Comment #4
uditrawatMinor fix on the patch.
Comment #5
christianadamski commentedIs this well enough tested to be merged? It is separately fixed in v4.
Comment #6
carma03 commented@ChristianAdamski just in case, the patch 3163657-4.patch could not be applied at least since 3.7 version.
Comment #7
christianadamski commentedThis is fixed in 4.x already and won't ne handled anymore in 3.x