Total Complexity | 6 |
Complexity/F | 1.2 |
Lines of Code | 35 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | const targets = Array.from(document.body.querySelectorAll('input[data-mapsfield=mapsfield]')); |
||
2 | const latField = document.getElementById('GoogleMapsLatField'); |
||
3 | const lngField = document.getElementById('GoogleMapsLngField'); |
||
4 | |||
5 | let options = {}; |
||
6 | let autoComplete; |
||
7 | |||
8 | const fillAddress = () => { |
||
9 | const event = new Event('change'); |
||
|
|||
10 | const location = autoComplete.getPlace(); |
||
11 | const components = location.address_components; |
||
12 | |||
13 | latField.setAttribute('value', location.geometry.location.lat()); |
||
14 | lngField.setAttribute('value', location.geometry.location.lng()); |
||
15 | |||
16 | components.forEach((component) => { |
||
17 | component.types.forEach((type) => { |
||
18 | const field = document.getElementById(type); |
||
19 | if (field) { |
||
20 | field.setAttribute('value', component.long_name); |
||
21 | field.dispatchEvent(event); |
||
22 | } |
||
23 | }); |
||
24 | }); |
||
25 | }; |
||
26 | |||
27 | const mountMapsField = (mapsfield) => { |
||
28 | options = Object.assign(options, window.customisations); |
||
29 | autoComplete = new google.maps.places.Autocomplete(mapsfield, options); |
||
30 | autoComplete.addListener('place_changed', fillAddress); |
||
31 | }; |
||
32 | |||
33 | export default function() { |
||
34 | targets.forEach(mountMapsField); |
||
35 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.