Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI Autocomplete not triggering a search when entering a hitherto searched for term
    text
    copied!<p>I have a jQuery UI Autocomplete control that fires an Ajax request when minLength = 3. The problem is as follows: Say I enter "fic" as the initial search term - this is fine. The request fires and results are returned. I decide that I don't want to select any of the results and then re-enter the same search again (fic). This time no Ajax request fires!</p> <p>My code is shown below:</p> <pre><code>// ... do request $("#reportSearch").autocomplete({ delay: 50, minLength: 3, source: function(q, add){ $.ajaxSetup ({ cache: false}); $.ajax({ type: "GET", url: K_URL_REQUEST </code></pre> <p><br/> So basically the "source" callback is not fired in the second scenario I described above. It appeared that the reason for this was that the autocomplete control was holding onto the previous search term and because it matched - was not triggering a search: <br/><br/></p> <pre><code>// Taken from jquery-ui-1.8.4.custom.min.js if (a.term != a.element.val()) { // *** THE MATCH IS HERE //console.log("a.term != a.element.val(): "+a.term+", "+a.element.val()); a.selectedItem = null; a.search(null, c) // *** SEARCH IS TRIGGERED HERE } </code></pre> <p><br/></p> <p>In order to get it to fire each time, I simply reset the search term to null after a search returned. This way it worked as expected.</p> <p>The thing is I don't understand this behaviour. I would've thought each search should be distinct. There is no caching (or shouldn't be anyway).</p> <p>So although I've fixed my problem I keep feeling that I have missed something here.</p> <p>Any ideas anyone? Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload