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

StackOverflow https://stackoverflow.com/questions/21412738

  •  03-10-2022
  •  | 
  •  

Question

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...

Was it helpful?

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);  
  });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top