Utilizing Vue.js for enhanced user experience, implementing Bootstrap modal with Google Maps autocomplete

I recently set up a Bootstrap modal that includes an <input>. To enable Google autocomplete for it, I utilized the commonly known trick below:

.pac-container {
    z-index: 10000 !important;
}

However, I have encountered difficulty in getting the autocomplete feature to work within a nested Bootstrap Modal. Unfortunately, the z-index workaround doesn't seem to apply in this scenario.

<div class="modal fade" id="editItemModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div id="editItem" class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    Update Address <b>{{selectedItem.properties.NAME}}</b>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label class="sr-only" for="editItem_ADRESS1"></label>
                            <input v-model="selectedItem.properties.ADRESS1" type="text" class="form-control" id="editItem_ADRESS1" ref="editItem_ADRESS1" placeholder="{{selectedItem.properties.ADRESS1}}">
                        </div>    
                    </form>          
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-success btn-ok" @click="save_item()" data-dismiss="modal">Save</a>
                </div>
            </div>
        </div>
    </div>

Following the modal markup is the Vue object setup:

const editItem = new Vue({
            el: "#editItem",
            data: {
                items: null,
                selectedItem: null,
            },
            methods: {
                save_item() {
                    this.selectedItem = itemsList.selectedItem;
                    var ip = location.host;
                    $.ajax({
                        type: 'POST',
                        dataType: 'json',
                        url: 'http://' + ip + '/updateItem',
                        data: {
                              command: "edit_item",
                              item_id: this.selectedItem.id,
                              adress1: this.selectedItem.properties.ADRESS1
                        },
                        success: function (responseData) {
                            if (responseData.result === false) {
                                console.log(responseData.result);
                            }
                            else {
                                console.log("successfully updated");
                            }
                        },
                        error: function (error) {
                            console.log('error', error);
                            }
                        }); // end of ajax
                    } // end od save_item()
                } // end of methods
        });

Answer №1

After some investigation, I finally uncovered the root of the issue. It appears that Vue does not create the DOM object in time for the Google initAutocomplete() function to set up listeners.

Furthermore, my <input> was not triggering the Google geolocate() function as expected. Here is how the updated <input> now looks:

<div class="form-group">
    <label class="sr-only" for="edit-item_ADRESS1"></label>
        <input id="edit-item_ADRESS1" v-model="selectedItem.properties.ADRESS1" type="text" class="form-control" onFocus="geolocate('edit-item')">
</div>

The next step involved making a slight modification to the geolocate() function. I passed the action variable to the onFocus event and utilized it to identify which DOM object triggered the call.

if (action == "add-item") {
      autocomplete_add_item.setBounds(circle.getBounds());
}
if (action == "edit-item") {
      // we need to run initAutocomplete again after the DOM object was created by Vue
      initAutocomplete();
      autocomplete_edit_item.setBounds(circle.getBounds());
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues with TypeScript "Compile on save" functionality in Visual Studio 2015

The feature of "Compile on save" is not functioning properly for me since I upgraded to Visual Studio 2015. Even though the status bar at the bottom of the IDE shows Output(s) generated successfully after I make changes to a .ts file and save it, the resul ...

The feature to disable swiping with SwipeEnabled set to false seems to be

I am encountering an issue with react-navigation 5 in my react-native project. I am trying to disable drawer swipes while still allowing the user to close the drawer by clicking outside of it. I have researched this property in the react-navigation documen ...

Categorizing an Array based on an Object within the Arrays Object in Vue Storefront

Recently started working with VueStorefront and encountering an issue in my project. My goal is to organize the products in the cart using an accordion grouped by their type. To achieve this, I need to group the array based on product type, resulting in an ...

How can AngularJS effectively parse JSON data containing HTML elements?

We are experiencing difficulties in reading a json file containing html content. Here is the code snippet with the json data we are working with: Json data: { "aboutContent": { "listItems": [{ "title": "Investors", "de ...

Information is being received, but unfortunately, it cannot be displayed

Currently, I am experimenting with using the axios http request to showcase some data. My focus is on exploring how to exhibit api data on the client side with react. If you are interested in seeing my progress so far, feel free to check out the link belo ...

Select2 version 4.0.3 encountering issues when trying to automatically populate additional select2 fields with data fetched through ajax

I'm encountering an issue with Select2. Essentially, I need to populate other form fields with data retrieved from Select2's Ajax search. Even after following an example found here: Select2 4.0 - Push new entry after creation I'm still un ...

Implementing the MVC pattern in the app.js file for a Node.js and Express web application

After completing several tutorials on nodejs, mongodb, and express, I have gained a solid understanding of the basics such as: The main controller file being app.js. Third party modules stored in their designated node_modules directory. Template files pl ...

How to send route parameters to a controller function in ExpressJS

I'm currently working on setting up user authentication for my application using passport JS. I am facing a challenge in passing the passport variable between app.js, routes.js, and controller.js. Despite trying various approaches, I have been unsucce ...

JavaScript date input formatting with HTML

When using the input date picker in HTML, the default format displayed is MM-DD-YYYY. <input type="date" id="gdatum" /> Is there any method to change the mask to DD-MM-YYYY? ...

Can AJAX Delete requests be executed without using jQuery?

Is it possible to use AJAX delete request without using jQuery? My JSON object at localhost:8000 appears like this: { "Students":[{"Name":"Kaushal","Roll_No":30,"Percentage":94.5}, {"Name":"Rohit","Roll_No":31,"Percentage":93.5}, {"Name":"Kumar ...

Customize the styling of an individual 'LI' item within an array by utilizing Jquery

Just starting out with Javascript and jQuery. Created a basic image slider that's running into a jQuery problem. Here's the HTML for the image list: <div id = "slider-auto"> <ul class= "slides"> <li class = "slide"&g ...

Customize Vue.js: Disable Attribute Quote Removal for Individual Pages

We have a requirement to turn off the minify.removeAttributeQuotes property for certain pages. This is the content of my vue.config.js: const packageJson = require('./package.json') module.exports = { assetsDir: packageJson.name + &apos ...

Newbie in PHP: Techniques for transferring PHP variables between different sections of PHP code

In my project, I have a file named index.php which is responsible for uploading files to the server and setting PHP variables such as $target_folder_and_file_name. This index.php file also includes the following line (originally it was in an index.html fi ...

Modify the colors of names within an array of point names and their corresponding y values using Highcharts

I am trying to customize the color for each point in an array based on its name and y value. This is what I have so far: (function(H) { H.wrap(H.Series.prototype, 'getColor', function(proceed) { this.color = generateColorForString(this.na ...

What is the best way to incorporate products as components into the cart component?

ProductCard import React from 'react'; import { Card, Container, Row, Col, Button} from 'react-bootstrap'; import Cart from './Cart'; import './ItemCard.css'; function ProductCard(props){ return( <Car ...

Does the onchange function in the dropdown list only work when the first item is changed?

Here is a snippet of my HTML code featuring a list item generated from a database using a foreach loop: <select class="form-control select" id="inventoryitem" name="inventoryitem" onchange="getunit();"> <option>---Select an item---</o ...

Step-by-step guide on setting up a weekly recurrence using a datepicker

Can anyone help me figure out how to create an event repetition feature using a datepicker and a <v-text-field>? Essentially, I want users to be able to choose the number of weeks that the event will repeat for. For example: If I select Monday, Octo ...

Passing null as a parameter in ngResource AngularJS

I am currently utilizing ngResource from AngularJS 1.2.1, and I'm encountering an issue when attempting to include null as a parameter value in a PUT request. It seems that Angular ignores the parameter entirely and does not send it along with the req ...

Storing row details in Vue.js based on selected options from a dropdown menu

Displayed below is my code that generates a dynamic table. I am looking to save specific rows based on the selection made from a dropdown menu and then clicking on an update button. <b-field> <b-select name="contacted" id="" ...

How can I resize an element using jQuery resizable and then revert it back to its original size with a button click?

I need help figuring out how to revert an element back to its original size after it has been modified with .resizable. I attempted the following: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//code. ...