craft-locate
craft-locate copied to clipboard
Locate field not working due to the "prefix" being empty in the options object
Google maps could not bind any events to the Locate input field due to a mismatched ID selector. "prefix" in the data object is returning empty.
var input = document.getElementById(_this.options.prefix + _this.options.name + '-location');
This seems to be a Craft v3.5+ issue. I'm running Locate v2.1.1 on multiple sites and this only occurs on newer Craft builds.
Seems like this author don't seems to care... I got the same issue.
@alexgilbertDG
I added my own temporary fix to get the location selector to work. I don't think this is a sustainable solution but it allows me to update location entries in Craft.
File to update /vendor/swixpop/locate/src/assetbundles/locatefieldfield/dist/js/LocateField.js
Update $.fn[pluginName] function to the following
$.fn[pluginName] = function (options) {
// Temporary fix for Locate
var fixNamespace = options.namespace;
var fixPrefix = fixNamespace.replace('locationFinder','');
options.prefix = fixPrefix;
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName,
new Plugin(this, options));
}
});
};
@tysonyau if it's of any help for you, I created a working fork since I couldn't reach the original author and he hasn't been active on Github since 2019.
To remove:
composer remove swixpop/locate
Then add:
composer remove lenvanessen/locate