Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Bryn Kaufman on Jun 21, 2009 11:02
open dhtmlx forum
Why does readonly mode stop the filtering mode with the dhtmlXCombo?

When I enable readonly the filtering no longer works.

In the script below if I am not using readonly filtering works, so I can enter 11 as an example and see the first two options. Then when I add the readonly and enter 11 only the first option comes up, I can no longer see the 2nd option even though it starts with 11.

<script>
var z=new dhtmlXCombo("combo_zone2","alfa3",200);
z.addOption([[1,1111],[2,1122],[3,1333],[4,4444],[5,5555]]);
z.enableFilteringMode(true);
z.readonly(true);
</script>

Answer posted by Alex (support) on Jun 22, 2009 00:45

Hello, 

this is correct behaviour as read-only mode doesn't disable combo input for typing.

You can try to use the following approach instead of readonly() - in this case a user will be allowed to enter only values that are presented in list:

var val='';

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

Answer posted by Bryn Kaufman on Jun 22, 2009 10:00
This allows anything to be typed in but removes it after they exit the combo box which would confuse the user as they would wonder why what they typed just disappeared.  As you mention above, I need to allow the user to enter only values that are in the list, if they start typing something that is outside the list it needs to not allow that.
Answer posted by Alex (support) on Jun 23, 2009 01:18

There is  "onKeyPressed" event handler you can use your approach that will check options in combo:

var text = "";

combo.attachEvent("onKeyPressed",function(code){
  if(checkText(this.getComboText())) text=this.getComboText();
  else this.setComboValue(text);
})