Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by kevhender on Mar 27, 2009 10:50
open dhtmlx forum
Filtering while only allowing valid input

Hi,

I'm trying to get the combo to allow filter mode, but only allow the user to keep typing if their previous character continues a valid selection. So, if the options were:

Afghanistan
Albania
Algeria
Bulgaria

When the user typed "A", the first 3 options appeared. Then when the user typed "l" ("Al" total), only options 2 and 3 appear. Then, if the user typed "d", the "d" doesn't actually show up, and the input box still just says "Al" and shows options 2 and 3.

Is this possible? Thanks!

Answer posted by Alex (support) on Mar 30, 2009 06:18

Hi, 

Combo API doesn't allow to do exactly what you described. But the following approach is possible:

var val ="";
combo.attachEvent("onChange",function(){
 if(!combo.getOptionByLabel(combo.getComboText())){
  combo.setComboValue(val);
 }
 else val = combo.getActualValue()
})

When a user enters text which doesn't belong to combo options, the previous selection will be restored.