Skip to content
Snippets Groups Projects
Commit 668bc945 authored by Regis Houssin's avatar Regis Houssin
Browse files

Qual: add cache in autocompleter for minimize the request

parent 05db777d
No related branches found
No related tags found
No related merge requests found
...@@ -88,9 +88,20 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='') ...@@ -88,9 +88,20 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
$script.= '<script type="text/javascript">'; $script.= '<script type="text/javascript">';
$script.= 'jQuery(document).ready(function() { $script.= 'jQuery(document).ready(function() {
var cache = {};
jQuery("input#search_'.$htmlname.'").autocomplete({ jQuery("input#search_'.$htmlname.'").autocomplete({
source: function( request, response ) { source: function( request, response ) {
if (cache.term == request.term && cache.content) {
response(cache.content);
return;
}
if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
response($.ui.autocomplete.filter(cache.content, request.term));
return;
}
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){ jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
cache.term = request.term;
cache.content = data;
response( jQuery.map( data, function( item ) { response( jQuery.map( data, function( item ) {
if (data.length == 1) { if (data.length == 1) {
jQuery("#search_'.$htmlname.'").val(item.value); jQuery("#search_'.$htmlname.'").val(item.value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment