Search code examples
dwr

Autocompleter DWR: how to make search engine starts only when at least three characters are typed?


The following code is taken from the link: http://tsamuel.wordpress.com/2007/05/17/direct-web-remoting-a-tutorial/

It is an autocomplete text field that uses DWR.

 <script type="text/javascript">
         new Autocompleter.DWR('personName', 'personListDiv', updatePersonList,{ valueSelector: function(obj){ return obj.name; },
    partialChars: 2, choices: 10 }); </script>

The updatePersonList:

function updatePersonList(autocompleter, token) {
        DWRPersonService.getAllPersons(function(data) {  autocompleter.setChoices(data);  });
}

What I would like to do is to configure the code above in a way that the search only starts when three characters are typed (at least). Tried to change partialChars value but it doesn't seem to work...


Solution

  • I don't know how partialChars works, i would do something like

    function updatePersonList(autocompleter, token) 
    {
      if(token.length < 3) return;
    
      DWRPersonService.getAllPersons(function(data)
      {
         autocompleter.setChoices(data);  
      });
    }