Resource icon

[J] Auto Complete Location 1.3.3

No permission to download
Thank you, I am trying to download but xenforo says that I need more than 0 posts. I just posted in the general xenforo forum. Will this fix it? thank you
What is your username on my site ?
It's really long past the time that you should have lifted this silly requirement.
There is already no such requirements for registered users on my site. Maybe it's just his registration might be rejected😅
 
I don't know if this addon is still maintained, but it became apparent today that it has a template modification to member_edit which adds the auto-lookup to the Location field. The issue with this is that this form is not used by the user, it's used by staff, which means it's updating the location of the user being edited with the location of the staff member doing the editing, which is obviously not desired. This template modification should just be removed.
 
I have found a bug. When it auto fills my location when testing, it returns
[the correct city], England,United Kingdom
Note there is no space between England, and United Kingdom. There should be a space.

The addon loads google maps api across all the forum pages and hurts the score on Google Pagespeed. It should load it on the registration page only
View attachment 250640
Has this ^ been fixed?
 
Note there is no space between England, and United Kingdom. There should be a space.
I've had that issue also--no space before the country in my case.

But not any longer since it stopped working. Due to this:

1676821550091.webp

I hate JavaScript and Google's rubbish documentation is confusing, so I didn't attempt to fix this myself yet.

The addon loads google maps api across all the forum pages and hurts the score on Google Pagespeed. It should load it on the registration page only

I wonder if the code loading Maps API could be enclosed in a conditional so it loads only on the registration page. Although the way the add-on is written, it can be used in custom fields in a user's profile as well as custom thread fields (which we would use in Classified Ads for instance), so the API would need to be present when threads are created unless we had an option to defeat that feature.

This really should be a core feature. I can't tell you how many times staff gets frustrated because members post nonsense in their location...
 
So, this:

HTML:
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDCAMt0cP_ljx5SmpQ2PKYkTB8ijuG7eOo&libraries=places&language=en"></script>

There is no &callback= here, but who knows what it is supposed to be? 🤷‍♂️ Google, vague as always...


But I am thinking that the following, or variation thereof, might work (this is untested!) to load the Maps API only on the account details page based on this post by @Russ:

HTML:
<xf:if is="$xf.reply.template == 'account_details'">
  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDCAMt0cP_ljx5SmpQ2PKYkTB8ijuG7eOo&libraries=places&language=en"></script>
</xf:if>

It would require editing one of the PAGE_CONTAINER templates in the add-on where the above HTML loads the Maps API. Very easy to do, actually.

But, it would also break the functionality of using the add-on with custom thread fields. So, there is that.

BTW, another note about Google Maps--I went to check the API Credentials and now it is telling me I need to sign up for a billing account. Guess it's not going to be free anymore?
 
I don't know if this addon is still maintained, but it became apparent today that it has a template modification to member_edit which adds the auto-lookup to the Location field. The issue with this is that this form is not used by the user, it's used by staff, which means it's updating the location of the user being edited with the location of the staff member doing the editing, which is obviously not desired. This template modification should just be removed.

For now I would just turn off the template edit if it does not function how you'd like. This works for me:

1676824072330.png

I don't think I've had that problem, though--does the add-on somehow do automatic detection of a user's location? I've used it to populate the field with test data from around the world (using my test accounts on a development installation) and didn't find that it was automatically being chosen for me.

Or maybe it's the browser's autofill doing this? I've occasionally seen my browsers have issues with similar location fields using a similar Maps API and using autofill data.

If that is the case, using autocomplete="off" in that user edit form's HTML input field might be what is needed. I don't even know if this works in a template, given how the form field is created, but it's possible it could be done in the member_edit template mentioned above:

HTML:
<xf:textboxrow name="profile[location]" id="location" value="{$user.Profile.location_}"
                maxlength="{{ max_length($user.Profile, 'location') }}"
                label="{{ phrase('location') }}" autocomplete="off" />
<xf:js>
<xf:include template ="j_acl_location"/>
    </xf:js>

I don't know if autocomplete="off" affects how the field works, though...again, the above is untested.
 
I don't think I've had that problem, though--does the add-on somehow do automatic detection of a user's location? I've used it to populate the field with test data from around the world (using my test accounts on a development installation) and didn't find that it was automatically being chosen for me.

Or maybe it's the browser's autofill doing this? I've occasionally seen my browsers have issues with similar location fields using a similar Maps API and using autofill data.
It does when the "Auto Fill Location" option is enabled, yes, so it's not browser autofill, it's the addon.

Also we already have disabled the template modification, the problem is that if this option is enabled it will auto-populate the location of the user you're editing with your location. Also I don't think the location is generally something that would need to be autocompleted when edited a user even if using the typeahead lookup. At the very least it needs to not auto-complete it on load. If people don't realise it's doing this then every time they've edited a user as a moderator, the user's location has also been changed.
 
It does when the "Auto Fill Location" option is enabled, yes, so it's not browser autofill, it's the addon.
That makes sense--we do not use that feature. I forgot it was an option.

The best solution in the future would be to use some conditionals in the add-on so that you could still use the API lookup in user editing if needed, but disable autofill. As our staff would rarely edit the location, I will leave that template edit switched off as well.
 
Autocomplete hasn't been working for me. Has anyone else had an issue? This is what I get now (after a repair to one of the template modifications):

1676950835138.png




The error above did not appear until I first fixed a template modification--it was not being applied. In the account_details template modification, this is Find:

HTML:
<xf:textboxrow name="profile[location]" value="{$xf.visitor.Profile.location_}"
                    maxlength="{{ max_length($xf.visitor.Profile, 'location') }}"
                    label="{{ phrase('location') }}" />

Yet in the account_details template, this is the code I am seeing. The hint=.............. line is added. I do not modify any existing templates except through the template modification system, so I don't know if this is an addition made to the code in recent XF versions or not. (Can anyone else verify if this matches their 2.2.12 version? I have so far checked two 2.2.12 templates and they are the same.)

HTML:
<xf:textboxrow name="profile[location]" value="{$xf.visitor.Profile.location_}"
                    maxlength="{{ max_length($xf.visitor.Profile, 'location') }}"
                    hint="{{ $xf.options.registrationSetup.requireLocation ? phrase('required') : '' }}"
                    label="{{ phrase('location') }}" />

If I change Find: to the code above, I get a match. 👍 However, Replace: needs to be modified as well, adding the id="location" parameter. Giving us this:

HTML:
<xf:textboxrow name="profile[location]" id="location" value="{$xf.visitor.Profile.location_}"
                    maxlength="{{ max_length($xf.visitor.Profile, 'location') }}"
                    hint="{{ $xf.options.registrationSetup.requireLocation ? phrase('required') : '' }}"
                    label="{{ phrase('location') }}" />
<xf:js>
<xf:include template ="j_acl_location"/>
</xf:js>


This does not, however, fix the addon. I get the Google Maps error I pasted above.

In the console, I get the following error:

Loading the Google Maps JavaScript API without a callback is not supported: https://developers.google.com/maps/documentation/javascript/url-params#required_parameters

I dug through Google's documentation and found this. We are using the Places API.


This is the code they say will load the Places API:

HTML:
<script async
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initMap">
</script>

So, in the template modification, &callback=initMap is missing. However, initMap needs to be in the JavaScript in this addon, as adding &callback=initMap to the src above throws an error in the console:

Code:
{
    "message": "initMap is not a function",
    "stack": "Error
    at _.ue.captureStackTrace (https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&language=en&callback=initMap:273:1891)
    at new _.ue (https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&language=en&callback=initMap:94:455)
    at _.ve (https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&language=en&callback=initMap:95:98)
    at lea (https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&language=en&callback=initMap:226:99)
    at https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&language=en&callback=initMap:225:232",
    "name": "InvalidValueError"
}

So that's where it's at right now. Searching Google again, this page was no help:

 
Last edited:
I have found a bug. When it auto fills my location when testing, it returns
[the correct city], England,United Kingdom
Note there is no space between England, and United Kingdom. There should be a space.


Has this ^ been fixed?

I just tested this, and it works. Wrapping the script in this conditional will make it load only for the account details page.

HTML:
<xf:if is="$xf.reply.template == 'account_details'">
  <script .....................></script>
</xf:if>

You would need to edit the template modification PAGE_CONTAINER for this addon. There are two--one of them adds the copyright info to the footer. The other adds the <script>--that is the one you want.

Caveat: This addon has a feature to use a custom thread field to autofill a location; this modification will make that feature stop working.

(In my case, though, this addon is not working, but at least I get the browser console errors only on the account details page, vs. all pages on the site.)
 
I have other plans on how to use the API in this addon. Probably be switching the API calls to be made via guzzle client and using caching in between for making less number of API callbacks to google or any other service provider! :)
Shweet! 👍

Google now makes you setup a billing account for using the Maps API, but gives you $200 in free credit each month, apparently. Even on a busy forum, though, how often are members going to add or change their locations? So I'm not too worried about it even if we have to stick with the current API.
 
Does anyone have a workaround for selecting the location.

Currently if using google maps API to complete the location during registration, when the location is types, the return key does not save, it must be selected from the list using a mouse click. It would be helpful if this could be selected using the keyboard.
 
Does anyone have a workaround for selecting the location.
I think i know the issue. Someone once requested a change in addon to allow only the input that is clicked and selected by user from dropdown, so that no one can enter anything random. I will check and update you on this :)
 
Top Bottom