Gif loading when searching

Asked

Viewed 111 times

0

Hello

I am implementing that self-cmplete

And I would like that while the system searches the items, it show a gif by clicking on the corner of the input.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
  </script>
</head>
<body>
 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>
 
 
</body>
</html>

The line below in css works, but I don’t know where to insert:

.ac_loading {
    background: white url('indicator.gif') right center no-repeat;
}

That one tutorial appears, only that his code is old and gives conflict in some functions, that do not work but has what I would like to do:

$.Autocompleter.defaults = {
    inputClass: "ac_input",
    resultsClass: "ac_results",
    loadingClass: "ac_loading",

For example, this last code gives the following error:

Cannot read property 'opera' of undefined

That’s it!

  • 2

    I don’t know how to do it correctly, but so you can use search to start loading, and select to finish loading. https://stackoverflow.com/questions/13127917/how-do-i-add-an-event-when-jquery-autocomplete-results-are-complete https://stackoverflow.com/questions/24626591/lazy-initialization-of-jquery-ui-autocomplete

  • Good is working, just missing I can to lose the focus also disappear the loading, but your idea is working

  • Ready, please add as answer that worked, so I mark as solved

  • Glad you could help...

1 answer

1


You can use the methods search to start loading, and select to finish it from the autocomplete.

$("#searchFirstTransactionStateInfo_searchPartnerId").autocomplete({
   search: function( event, ui ) {
        iniciaLoading();
    },
    select: function(event, ui) {
        finalizaLoading();   
    }
});

Useful links:

How to inialize: https://stackoverflow.com/questions/24626591/lazy-initialization-of-jquery-ui-autocomplete

How to end: https://stackoverflow.com/questions/13127917/how-do-i-add-an-event-when-jquery-autocomplete-results-are-complete

I hope I’ve helped.

  • 1

    Excellent. It worked out

Browser other questions tagged

You are not signed in. Login or sign up in order to post.