How to disable submit when selecting an address?
Support › MB Geolocation › How to disable submit when selecting an address?Resolved
- This topic has 7 replies, 3 voices, and was last updated 5 years, 2 months ago by
ComSi.
-
AuthorPosts
-
October 8, 2019 at 2:05 AM #16422
brandonjp
ParticipantCurrently if a user selects an address using the keyboard (using arrow keys and then hitting the return/enter key on an address) it submits the entire form & causes the page to page to refresh (if Post) or adds the new term (if Taxonomy)
Is there a Meta Box way of disabling form submission on return when selecting an address with the keyboard?
October 8, 2019 at 3:31 PM #16429ComSi
ParticipantI'm basically having the same problem. When using the [enter] key I would expect to have the option selected but the complete page form is actually submitted.
Tried setting a
return false
on the input field that is the parent of autocomplete pop-down, but apparently that is not the element where we can check on the keyup event for that pop-down.October 9, 2019 at 2:56 AM #16441brandonjp
ParticipantOn my sites, I'm currently using this ? chain which disables autocomplete on the address fields (in Chrome) and prevents the return key:
jQuery('form#post input[id^=address][type=text]').attr('autocomplete', 'new-password').keypress(function(e) { if (e.which == 13) return false; });
A few other options for this...
1️⃣
This ? disables submission anytime the Enter/Return key is pressed inside any form element (including Google Maps, but also on any other element):jQuery('.wp-admin.post-type-CUSTOMPOST form#post').keypress(function(e) { if (e.which == 13) return false; });
Here ? I'm targeting only the pages for my custom post type called
CUSTOMPOST
(so change that to your post type) or else just usejQuery('form#post')....
to attach this to all edit post screens.2️⃣
And for completeness... there is also Google Maps' prescribed way of adding event listeners: https://developers.google.com/maps/documentation/javascript/events#DomEvents ?google.maps.event.addDomListener(jQuery('#idOfTextInput')[0], 'keydown', function(e) { if (e.keyCode === 13) return false; });
Since we're in WordPress, I'm still using jQuery here ? you could easily write it with plain JS if needed. But since I'm still using jQuery here, I don't see the reason for using the Google Maps method.
October 10, 2019 at 3:56 PM #16459Anh Tran
KeymasterJust fixed this issue in the latest version of MB Geolocation.
October 10, 2019 at 4:28 PM #16463ComSi
ParticipantThat's great ?
Will this be available via the Composer repo soon? Tried updating but there were no available yet.
January 29, 2020 at 7:37 PM #18054ComSi
ParticipantDid the fix actually made it to production @Anh Tran?
When I press [enter] in this field, the full page will be submitted and reloads before the other (bind-)fields are populated.
I run Geolocation version 1.2.5, I believe that is the latest available, composer does not update it.
January 31, 2020 at 12:49 PM #18073Anh Tran
KeymasterThe latest version is 1.2.6. It's already available since October last year.
If you use Composer to update, please delete the vendor folder, clear Composer cache and run
composer install
again. For details, please see this docs.January 31, 2020 at 3:09 PM #18077ComSi
ParticipantThanks, the clear cache fixed it. We tried to update this but it stays on version 1.2.5.
Now it's on 1.2.6 it works like a charm. Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.