Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The Find address on map button does not work after failed form validation.
- Download latest stable Drupal 7.41 at the moment.
- Download latest dev version of the module 7.x-2.x.
- Create a content type and assign a location field type, using Location field widget for input .
- Open node/add/YOUR-CT page and hit SAVE (the title validation will fail or something else)
- Go to the fields widget enter a valid address and click the "Find address on map" button.
- Ha... Nothing happens... No error, no marker on the map...
The reason is that the JS added for the widget in the location_gmap_find_address_field_widget_form_alter method is missing. When the form validation fails, the form definition is extracted from the form cache, so the code that adds the JS through drupal_add_js call is not executed at all, resulting in not adding the JS to the page.
Proposed resolution
Change the alter so that it does not use the drupal_add_js, but the element's #attached property.
Remaining tasks
Review(s), RTBC, Commit.
User interface changes
None.
API changes
None / Small (way of adding JS resource to the page...)
Comment | File | Size | Author |
---|---|---|---|
#3 | gmap-field-widget-location-field-missing-javascript-file-2605496-3-D7.patch | 1008 bytes | ndobromirov |
Comments
Comment #2
ndobromirov CreditAttribution: ndobromirov at FFW commentedUpdated to assign to the correct module...
Comment #3
ndobromirov CreditAttribution: ndobromirov at FFW commentedHere is a patch implementing the proposed solution. It fixes the issue for me.
The works and finds addresses on the map even after failed form validation.
Comment #4
ndobromirov CreditAttribution: ndobromirov at FFW commentedClean-up issue summary.
Comment #5
podarokThanks, merged