Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Geoff Walker on Jul 15, 2009 08:07
open dhtmlx forum
Disallow selection of dhtmlxcombo with checkboxes

Hi,
How can I disallow any selection in a dhtmlxcombo with checkboxes? I want the item at index 0 to always remain as the selected item, but allow users to check or uncheck other items in the list without making a selection.
Thanks,
Geoff
Answer posted by Alex (support) on Jul 15, 2009 08:57

hello,

you can try to use the following approach (you should use the attached file instead of the original one): 

combo.attachEvent("onCheck",function(val){

  if(combo.getIndexByValue(val)==0) return false;

  else return true;

})

Attachments (1)
Answer posted by Geoff Walker on Jul 15, 2009 10:32

Actually, that's not quite what I'm looking for.  I don't want to prevent the user from checking any of the checkboxes; I want to prevent them from changing the selected item in the combo.  I'm basically trying to disable any "onChange" event.  My preference would be that nothing in the list even gets highlighted.  Checking and unchecking checkboxes - yes, selecting item in the list and changing selected item - no.

Also, if I create dhtmlxcombo objects using dhtmlXComboFromSelect, and storing them in an ajax prototype Hash collection, can you think of some way that I can access the proper one later when the "onBlur" event occurs?

Example code: 

    var multiCombos = new Hash();  //Ajax prototype object
    var filters = document.getElementsByClassName('dhxfilter');  //my code creates this classname
    for(var i = 0; i < filters.length; i++) {
        if(filters[i].id.substring(filters[i].id.lastIndexOf("_")) == "_multicombo") { //all "multi" html select controls will have "_multicombo" as part of the id
            var tmpcombo = new dhtmlXComboFromSelect(filters[i].id);
            tmpcombo.attachEvent("onBlur",doSomething);
            multiCombos.set(filters[i].id, tmpcombo); //add combo to Hash, key=original select id

        }
    }

When the "onBlur" event occurs, can you think of some way for me to know which combo caused the event and how I can use that knowledge to access the right object from the Hash?  Is there some other value I can use for the key in the Hash object that I can find on the "onBlur" event?

Thanks,

Geoff

Answer posted by Geoff Walker on Jul 15, 2009 15:04

Never mind about my second question.  I approached it all in a different manner by changing the "onBlur" event in your code to pass the dhtmlxcombo object.  Now I am able to do what I want to with the object without holding each one in the Ajax prototype Hash. 

I am still looking for an answer to the first question about disallowing a selection.

Thanks,

Geoff

Answer posted by Alex (support) on Jul 16, 2009 05:04

Hello,

it isn't possible to prevent selection in combo. Probably it will be better to use another component in this case or for example absolute-positioned container as a drop-down with checkboxes.

If you using combo is necessary, you can try to use the following approach to display in header input always the same text and don't highlight the option while scrolling:

 - comment the css class in the dhtmlxcombo.css

.dhx_selected_option{
 background-color:navy;
 color:white;
}

- use onChange and onSelectionChange events

combo.attachEvent("onChange",selectVal)
combo.attachEvent("onSelectionChange",selectVal)
function selectVal(){
 window.setTimeout(function(){
  combo.setComboText(some_text_here);
 },1)
}