I'm using Ajax.Autocompleter for a file browsing control, and it's mostly working; except when the user is a bit too quick with a tab or return: If you type a few characters into the box, and then type TAB before the Ajax request has come back with the list, the TAB is not captured, but just does the default browser 'advance to next input' - and cancel the Ajax request, so the autocomplete list never appears. With CR it doesn't advance to the next input, but it still cancels the request. So, for example, I type old and it comes back with oldstruct (the only option) and if I then hit TAB or CR it puts that into the text field and generates other data from it. But if I type 'old<CR>' quickly enough that the Ajax hasn't returned when I enter the CR, it never does return, and I end up with 'old' in my input field. I've checked, and this is the behaviour of the demo at http://demo.script.aculo.us/ajax/autocompleter. I guess it hasn't been a problem, because most of the time you will be waiting to check the options before making a selection - but I'm implementing filename completion, where people often know there's only one match, and type ahead. In some ways worse is what happens if I've already got something in the text box. My afterUpdateElement function updates a table elsewhere on the page, but leaves the focus on the autocomplete text input, so that having selected a directory, you can continue with the autocompletion. If you enter '/', my Ajax backend will return all the directories within that directory. If at this point you type a couple of characters (meaning to select one of the options now offered) and then hit TAB or CR before the Ajax has returned, it takes the TAB or CR as selecting the current choice from the autocomplete list, and then appends the characters you've typed on it So with oldstruct selected in the text field, I type '/' and it returns oldstruct/empty oldstruct/testsource in the autocomplete list. If I type 'te' and wait, it will update the list to 'oldstruct/testsource' only, and I can choose that by CR or TAB. But if I type 'te<TAB>' quickly, it appears to - take the current selection - append the letters I've typed - cancel the Ajax request, so I end up with oldstruct/emptyte in my Text box! Has anybody else met these problems and thought of a way round them? Or is there a different way to do this. (I do, if at all possible, want to mimic the behaviour of shells like Bash, where you can type TAB and get the next level in the path if it is unique).
on 2008-06-26 13:57
on 2008-06-26 14:10
Should have said - I'm using Firefox (3.0 actually). In IE6 it's the same, except that TAB doesn't appear to be intercepted by the autocompleter at all.