Bootstrap 3 typeahead.js - remote url attributes -
i'm trying call remote url added attributes url.
for have working:
$('#league').typeahead({ remote: '/typeahead/get_league?query=%query', limit: 10 });
now this:
$('#league').typeahead({ remote: function () { var q = '/typeahead/get_league?query=%query'; if ($('#sport').val()) q += "&sport=" + encodeuricomponent($('#sport').val()); return base_url + q; }, limit: 10 });
i add attribute 'sport' url can narrow down query on backend. tried code above js error.
the previous version of bootstrap typeahead allowed type of setup. useful update remote url every time key hit.
any idea how make work version ?
remote
exclusively typeahead.js (not part of bootstrap). not using remote
correctly, can either string or object, not function.
when need change request url, can use replace
:
$('#league').typeahead({ remote: { url: '/typeahead/get_league?query=%query', replace: function () { var q = '/typeahead/get_league?query=%query'; if ($('#sport').val()) { q += "&sport=" + encodeuricomponent($('#sport').val()); } return base_url + q; } }, limit: 10 });
check docs here
hope helps.
Comments
Post a Comment