Skip to content

Commit

Permalink
Setup method will accept element not the id of element.
Browse files Browse the repository at this point in the history
  • Loading branch information
phuclh committed Apr 29, 2021
1 parent 41779be commit 5a2cc47
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions resources/js/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const Address = (function () {

let autocompleteService;
let placesService;
let predictionListElementId;
let placeElementId;
let predictionListElement;
let placeElement;

let resetSessionToken = function () {
let sessionToken = new google.maps.places.AutocompleteSessionToken();
Expand All @@ -38,7 +38,7 @@ const Address = (function () {

window.initGoogleMapAutocomplete = function () {
autocompleteService = new google.maps.places.AutocompleteService();
placesService = new google.maps.places.PlacesService(document.getElementById(placeElementId));
placesService = new google.maps.places.PlacesService(placeElement);

resetSessionToken();
};
Expand Down Expand Up @@ -124,11 +124,11 @@ const Address = (function () {
};

let showPredictions = function () {
document.getElementById(predictionListElementId).classList.remove('invisible');
predictionListElement.classList.remove('invisible');
};

let hidePredictions = function () {
document.getElementById(predictionListElementId).classList.add('invisible');
predictionListElement.classList.add('invisible');
};

let addGoogleMapScript = function (key) {
Expand All @@ -143,8 +143,8 @@ const Address = (function () {

let setup = function (settings) {
// Assign essential element.
predictionListElementId = settings.predictionListElementId;
placeElementId = settings.placeElementId;
predictionListElement = settings.predictionListElement;
placeElement = settings.placeElement;

// Add Google Map script.
addGoogleMapScript(settings.googleApiKey);
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/Address/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export default {
places.setup({
googleApiKey: Nova.config.googleMapApiKey,
predictionListElementId: 'results-list',
placeElementId: 'attributions'
predictionListElement: document.getElementById('results-list'),
placeElement: document.getElementById('attributions')
});
this.placesAutocomplete = places;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class="w-full px-2 py-1 focus:outline-none text-gray-700 ring-1 ring-gray-300 ro
window.onload = function () {
Address.setup({
googleApiKey: '{{ config('google-api.services.places.key') }}',
predictionListElementId: 'results-list',
placeElementId: 'attributions'
predictionListElement: document.getElementById('results-list'),
placeElement: document.getElementById('attributions')
});
const addressInput = document.getElementById('search-bar');
Expand Down

0 comments on commit 5a2cc47

Please sign in to comment.