I have a website with Bootstrap framework. I have two very nasty input fields I'm stuck with, because I can't get them to work properly...
One is this Bootstrap Typeahead input field:
<input type="text" id="typeahead" name='name' placeholder='The name' class="form-control" data-provide="typeahead" autocomplete="off" />
The other is this dropdown list:
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" id="dates-dropdown-button" type="button" data-toggle="dropdown" href="#">
<?=$reminder_table_th_date?>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" id="name-dates-dropdown">
</ul>
</div>
(the <li>
list is populated via Ajax call)
With both I want to do: if I select one item either on the ajax dropdown field with the typeahead or with the dropdown list the selected item should be the value what the field is showing. I tried many-many ways, for example:
How to Display Selected Item in Bootstrap Button Dropdown Title
Bootstrap typeahead - How to set the default value manually
but none of them is working and I don't know why. I'm not a JS/jQuery guru at all, but that's just suspicious. Where exactly should I place the jQuery code for this functions and how?
PS: Firefox Firebug isn't showing any JS errors, they just don't do anything, the values aren't set OR the function for them isn't called.
This is the jQuery code for the typeahead Ajax call, the dropdown population (this is working well) and there is also one line where the typeahead value should be set (in the updater), but sadly that's not working:
<script type="text/javascript">
$(document).ready(function() {
$('#typeahead').typeahead({
source: function (query, process) {
$.ajax({
url: '/functions/name-autocomplete.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
process(data);
}
});
},
displayText: function(item) {
return item
},
updater: function (item) {
$('#typeahead').typeahead('val', item);
$.ajax({
url: '/functions/name-dates-autocomplete.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + item,
success: function(data) {
$('#name-dates-dropdown').html(data);
}
});
}
});
});
</script>