craft-locate icon indicating copy to clipboard operation
craft-locate copied to clipboard

Locate field not working due to the "prefix" being empty in the options object

Open tysonyau opened this issue 4 years ago • 3 comments

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.

tysonyau avatar Aug 18 '20 20:08 tysonyau

Seems like this author don't seems to care... I got the same issue.

alexgilbertDG avatar Aug 26 '20 15:08 alexgilbertDG

@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 avatar Sep 24 '20 16:09 tysonyau

@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

lenvanessen avatar Feb 24 '22 10:02 lenvanessen