Problem/Motivation

The Find address on map button does not work after failed form validation.

  1. Download latest stable Drupal 7.41 at the moment.
  2. Download latest dev version of the module 7.x-2.x.
  3. Create a content type and assign a location field type, using Location field widget for input .
  4. Open node/add/YOUR-CT page and hit SAVE (the title validation will fail or something else)
  5. Go to the fields widget enter a valid address and click the "Find address on map" button.
  6. 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...)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ndobromirov created an issue. See original summary.

ndobromirov’s picture

Project: GMap Addons » GMap Module
Version: 7.x-1.x-dev » 7.x-2.x-dev

Updated to assign to the correct module...

ndobromirov’s picture

Title: Field widget Location Field missing JavaScript file » Location field widget missing JavaScript file on failed form validation
Assigned: ndobromirov » Unassigned
Status: Needs work » Needs review
FileSize
1008 bytes

Here 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.

ndobromirov’s picture

Issue summary: View changes

Clean-up issue summary.

podarok’s picture

Status: Needs review » Fixed
Issue tags: -bug

Thanks, merged

  • podarok committed 56fc2a2 on 7.x-2.x authored by ndobromirov
    Issue #2605496 by ndobromirov: Location field widget missing JavaScript...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.