ASP.Net MVC5 app: Twitter.Typeahead not working.
Closed this issue · 1 comments
-> I installed Twitter.Typeahead via PM console
-> Added it to my bundles.config file
-> created a file for the required css as typeahead.css file:
.typeahead {
background-color: #fff;
}
.typeahead:focus {
border: 2px solid #0097cf;
}
.tt-query {
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}
.tt-hint {
color: #999
}
.tt-menu {
width: 422px;
margin: 12px 0;
padding: 8px 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}
.tt-suggestion {
padding: 3px 20px;
font-size: 18px;
line-height: 24px;
}
.tt-suggestion:hover {
cursor: pointer;
color: #fff;
background-color: #0097cf;
}
.tt-suggestion.tt-cursor {
color: #fff;
background-color: #0097cf;
}
.tt-suggestion p {
margin: 0;
}
->Below is my .cshtml form:
@{
ViewBag.Title = "New Form";
}
New Form
<div class="form-group">
<label>Movie</label>
<input type="text" value="" class="form-control" />
</div>
<button class="btn btn-primary">Submit</button>
->Below is my script section:
@section scripts
{
<script>
$(document).ready(function () {
var vm = {};
var customers = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/customers?query=%QUERY',
wildcard: '%QUERY'
}
});
$('#customer').typeahead({
minLength: 3,
highlight: true
}, {
name: 'customers',
display: 'name',
source: customers
}).on("typeahead:select", function () {
vm.customerId = customer.id;
});
});
</script>
}
->When i run the application and type in first 3 characters of the search word as specified in the minLength, nothing displays:
Has anyone been able to resolve this? i have checked several solutions on google none fixed the issue. I would appreciate if someone could assist to resolve this.
Thankfully I was able to resolve it. Did a little fix to the customer API and now it works