exposing/manipulating it via javascript

Sep 22, 2011 at 10:40 PM

Thanks for creating this control.  It's the only one that seems to work correctly in a sharepoint environment.  How can I expose this so I can manipulate it via javascript? like add values on the javascript side? hide and unhide?  Not sure if I have to do some special setup first...thanks.

Coordinator
Sep 23, 2011 at 12:27 PM

The 'behavior' object is created client-side for each control when the page loads. It manages the control behavior.

The object can be accessed as a global variable, e.g.

window.<%= dropDownCheckBoxes.ClientID %>.selectAll().

There're such functions  as selectAll(), deselectAll(), show(), hide(), clikcOk(), clickCancel() available for the behavior object. They cover functionality of the control  and where not tested as separate API but should work fine is used separately . You may find those functions in the 'DropDownScript.js' file if you open the source code solution.

Oct 21, 2011 at 8:17 PM

I am also confused on this it seems to have options to select all or none and do actions against the control but how would to select an item via javascript?

For instance I have 3 items in a list, Person1, Person2, Person3

How would I go about (in JavaScript) to say check Person2.

in drop down lists you could always say document.getElementById("ddlNames).value = celText; but I cant seem to figure out how to select a single or multiple items through JS

I've also tried the same with window.<%= dropDownCheckBoxes.ClientID %>

 but havnt had any luck....any insight would be great thanks

 

 

Oct 26, 2011 at 2:46 PM

If you inspect the html source, you should notice that the control uses a bunch of check boxes with an iterative numbering system.  ie.. somename_0, somename_1, somename_2

You can use dojo or jquery library to get an instance of the checkbox and iterate with a loop like:

            var i=0;     
            this.checkBox = dojo.byId("somename_" + i); //reference to the checkbox
 
            while (this.checkBox != null) {
 		
		
		if(this.checkBox.nextSibling.innerText=="Person2")
			this.checkBox.checked = true;
                //I only used the below line to grab the value, but haven't tried to actually set it, 
		//but above code assuming should work 
                //if (this.checkBox.checked == true)
                //    val += this.checkBox.nextSibling.innerText.split("-")[0] + ","; //this gets the selected value
 
                i++;
                this.checkBox = dojo.byId("somename_" + i); //document.getElementById should work too
            }

Maybe the author included the built in function to handle this, but I couldn't figure how to use it; this works. I will fix it when it breaks.

Nov 1, 2011 at 2:45 PM

I tried doing what you said via dojo and via varPerson = document.getElementById("somename_0");  however it always comes back "undefined" like it cant find it so ti never even gets inside of the while loop.... I also tried replacing somename_ with an actual name in the list but still did not have any luck. any ideas on what I might be doing wrong? Heres is my case statement that I am trying to implament this into... thanks for the help btw

 

 case "DropDownList-Assign":
                divEmployee = document.getElementById("divAssign");
                document.getElementById("ddlNames").value = celText;
                var i = 0;
                this.checkBox = dojo.byId("First LastName_" + i); //reference to the checkbox

                while (this.checkBox != null) {


                    if (this.checkBox.nextSibling.innerText == "First LastName")
                        this.checkBox.checked = true;
                    //I only used the below line to grab the value, but haven't tried to actually set it, 
                    //but above code assuming should work 
                    //if (this.checkBox.checked == true)
                    //    val += this.checkBox.nextSibling.innerText.split("-")[0] + ","; //this gets the selected value

                    i++;
                    this.checkBox = dojo.byId("somename_" + i); //document.getElementById should work too
                }

                               var myOldString = notes;
                var myNewString = myOldString;
                myNewString = myNewString.replace(/ /g, "");
                myNewString = myNewString.replace("", "");
                myNewString = myNewString.replace("", "");
                myNewString = myNewString.replace(/'/g, "'");
                notes = myNewString;
                var temp = new Array();
                var strTemp = "";
                temp = notes.split(']');
                for (i = 0; i < (temp.length - 1); i++) {
                    temp[i] = temp[i].replace("[", "");
                    strTemp = strTemp + temp[i] + "<hr><br>";
                }
                document.getElementById("lblNotes").innerHTML = strTemp;

                HideChkDiv();
                HideUploadDiv()
                break;
Nov 1, 2011 at 3:27 PM

actualy after digging into the run-time html source (I thought you were refering to the actual control source) I realized that the somename_ is actualy the name of the control so in my case I would call out this.checkBox = dojo.byId("cboAssign_" + i);

 

thanks for the help t4nguyen