In order to keep functionality even with javascript disabled, when the field has been rendered, with drupal.behaviors listen for the ".address-autocomplete-input" render - which is the google maps text field and should initially be hidden.
if found, create a "Appartment nr." field with classes ".initial-address-field" & ".appartment" and hide all the ".initial-address-field" class fields. (ALL WITHIN THE PARENT WRAPPER)
Assign an onChange listener to the apartment nr field which takes the route and street_number values from the google maps api field and combines them with the apartment nr in the ".street" field.
Initiate the Google maps API for the gmaps input field with allowed contries restriction if provided and assign an onChange listener, with which:
- hide and clear all of it's parent wrapper (with class ".address-autocomplete-wrapper) children input values that have the class ".initial-address-field" - this is just a redundancy mechanism for cases where the address is changed, so there would be empty values.
- for all the retrieved values assign them to the hidden input fields which actually carry the values
- - ".country" = country
- - ".state" = administrative_area_level_1
- - ".city" = locality
- - ".zip" = postal_code
- - ".street" = route + street_number (+local apartment field)
- unhide all ".initial-address-field" fields within the parent wrapper, which are required, but don't have a value.
- unhide the apartment nr field
Unhide the gmaps input field.
Comments
Comment #2
Alluuu commentedComment #3
Alluuu commented