JSFiddle - React, Tailwind, and code Playground
by muthusamy
HTML
<script src="https://raw.github.com/ivaynberg/select2/master/select2.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false&.js"></script>
<form action="#" id="Form" enctype="multipart/form-data" method="post"
accept-charset="utf-8">
<input name="data[Venue][name]" placeholder="venue" autofocus="autofocus"
required="required" title="venue is required" type="text" id="VenueName"
/>
</form>
<div id='mapHidden'></div>
CSS
/*
Version: @@ver@@ Timestamp: @@timestamp@@
*/
.select2-container {
width: 80%;
margin: 20px;
position: relative;
display: inline-block;
/* inline-block for ie7 */
zoom: 1;
*display: inline;
vertical-align: top;
}
.select2-container, .select2-drop, .select2-search, .select2-search input {
/*
Force border-box so that % widths fit the parent
container without overlap because of margin/padding.
More Info : http://www.quirksmode.org/css/box.html
*/
-webkit-box-sizing: border-box;
/* webkit */
-khtml-box-sizing: border-box;
/* konqueror */
-moz-box-sizing: border-box;
/* firefox */
-ms-box-sizing: border-box;
/* ie */
box-sizing: border-box;
/* css3 */
}
.select2-container .select2-choice {
display: block;
height: 26px;
padding: 0 0 0 8px;
overflow: hidden;
position: relative;
border: 1px solid #aaa;
white-space: nowrap;
line-height: 26px;
color: #444;
text-decoration: none;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
background-color: #fff;
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #eeeeee), color-stop(0.5, white));
background-image: -webkit-linear-gradient(center bottom, #eeeeee 0%, white 50%);
background-image: -moz-linear-gradient(center bottom, #eeeeee 0%, white 50%);
background-image: -o-linear-gradient(bottom, #eeeeee 0%, #ffffff 50%);
background-image: -ms-linear-gradient(top, #ffffff 0%, #eeeeee 50%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee', GradientType=0);
background-image: linear-gradient(top, #ffffff 0%, #eeeeee 50%);
}
.select2-container.select2-drop-above .select2-choice {
border-bottom-color: #aaa;
-webkit-border-radius:0 0 4px 4px;
...
JavaScript
jQuery(document).ready(function ($) {
$('#VenueName').select2({
minimumInputLength: 3,
maximumInputLength: 30,
maxItemsToShow: 5,
selectFirst: false,
query: function (options) {
var data = {
results: []
},
url = '/echo/json/',
country = 'us',
map = new google.maps.Map(document.getElementById('mapHidden')),
service = new google.maps.places.AutocompleteService(),
detail = new google.maps.places.PlacesService(map);
$.getJSON(url, {
q: options.term
}).done(function (records, statusText, jqXhr) {
$.each(records, function (i, record) {
data.results.push({
id: record.data.id,
text: record.value,
address: record.data.address,
country_id: record.data.country_id,
lat: record.data.lat,
lng: record.data.lng,
category_id: record.data.category_id
});
});
service.getPlacePredictions({
input: options.term,
types: ['establishment'],
componentRestrictions: {
country: country
}
}, function (predictions, status) {
if (status !== google.maps.places.PlacesServiceStatus.OK) {
return options.callback(data);
}
$.each(predictions, function (n, prediction) {
detail.getDetails({
reference: prediction.reference
}, function (details, status) {
if (status !== google.maps.places.PlacesServiceStatus.OK) {
return...