javascript - Google Place Autocomplete API dropdown does not show in Modal - Stack Overflow

I am new to working with bootstrap. I am trying to integrate Google JS Place Autoplete API with bootstr

I am new to working with bootstrap. I am trying to integrate Google JS Place Autoplete API with bootstrap 3.0 Modal.

Modal CSS:

#searchModal{
    z-index:1041 !important;
}
.modal-header, h4, .close {
    background-color: #5cb85c;
    color: white !important;
    text-align: center;
    /*font-size: 30px;*/
}
.modal-footer {
    background-color: #f9f9f9;
} 
.modal-backdrop {
    opacity: 0.5 !important; 
}

Autoplete JS:

function initMap() {
var oInput = document.getElementById('ocity-input');

var oSearchBox = new google.maps.places.SearchBox(oInput);

oSearchBox.addListener('places_changed', function() {
    var places = oSearchBox.getPlaces();

    places.forEach(function(place) {
        console.log(place.name);
        console.log(place.place_id);
    });
});
}`

Autoplete CSS:

@CHARSET "ISO-8859-1";
html, body {
    height: 100%;margin: 0;padding: 0;
}
.form-control {
    margin-top: 10px;
    border: 1px solid transparent;
    border-radius: 2px 0 0 2px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    height: 32px;
    outline: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#ocity-input {
    background-color: #fff;
    font-family: Roboto;
    font-size: 15px;
    font-weight: 300;
    margin-left: 12px;
    padding: 0 11px 0 13px;
    text-overflow: ellipsis;
    width: 300px;
}
#ocity-input:focus {
    border-color: #4d90fe;
}
.ocity-container {
    font-family: Roboto;
    z-index: 10000;
    display: block !important;
}

Modal Code:

<div class="container">
    <div class="modal fade" id="searchModal" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="padding: 35px 50px;">
                    <h4 style="text-align: center;">
                        <span class="logo">Name</span>
                    </h4>
                </div>
                <div class="modal-body" style="padding: 40px 50px;">
                    <form role="form">
                        <div class="form-group">
                            <input id="ocity-input" class="form-control" type="text" placeholder="Origin">
                        </div>
                        <button type="submit" class="btn btn-success btn-block">
                            <span class="fa fa-undo"></span> Lets Go
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
 </div>

I have tried multiple z-index help answers both on stackoverflow and the internet but they don't seem to work for me.

I am new to working with bootstrap. I am trying to integrate Google JS Place Autoplete API with bootstrap 3.0 Modal.

Modal CSS:

#searchModal{
    z-index:1041 !important;
}
.modal-header, h4, .close {
    background-color: #5cb85c;
    color: white !important;
    text-align: center;
    /*font-size: 30px;*/
}
.modal-footer {
    background-color: #f9f9f9;
} 
.modal-backdrop {
    opacity: 0.5 !important; 
}

Autoplete JS:

function initMap() {
var oInput = document.getElementById('ocity-input');

var oSearchBox = new google.maps.places.SearchBox(oInput);

oSearchBox.addListener('places_changed', function() {
    var places = oSearchBox.getPlaces();

    places.forEach(function(place) {
        console.log(place.name);
        console.log(place.place_id);
    });
});
}`

Autoplete CSS:

@CHARSET "ISO-8859-1";
html, body {
    height: 100%;margin: 0;padding: 0;
}
.form-control {
    margin-top: 10px;
    border: 1px solid transparent;
    border-radius: 2px 0 0 2px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    height: 32px;
    outline: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#ocity-input {
    background-color: #fff;
    font-family: Roboto;
    font-size: 15px;
    font-weight: 300;
    margin-left: 12px;
    padding: 0 11px 0 13px;
    text-overflow: ellipsis;
    width: 300px;
}
#ocity-input:focus {
    border-color: #4d90fe;
}
.ocity-container {
    font-family: Roboto;
    z-index: 10000;
    display: block !important;
}

Modal Code:

<div class="container">
    <div class="modal fade" id="searchModal" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="padding: 35px 50px;">
                    <h4 style="text-align: center;">
                        <span class="logo">Name</span>
                    </h4>
                </div>
                <div class="modal-body" style="padding: 40px 50px;">
                    <form role="form">
                        <div class="form-group">
                            <input id="ocity-input" class="form-control" type="text" placeholder="Origin">
                        </div>
                        <button type="submit" class="btn btn-success btn-block">
                            <span class="fa fa-undo"></span> Lets Go
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
 </div>

I have tried multiple z-index help answers both on stackoverflow and the internet but they don't seem to work for me.

Share Improve this question asked Mar 8, 2016 at 18:26 o12d10o12d10 7983 gold badges17 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The dropdown petes with the z-index of #searchModal (1041).

With the following CSS definition the dropdown should appear on top:

.pac-container {
    z-index: 1042;
}

Here's the fiddle. Please replace "YOUR_API_KEY" with one of your own.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745335087a4623064.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信