Is it possible to differentiate the user selection or programmatically selection of the items in the DropDownList?
Solution
Yes, It’s possible to differentiate the selection of items in DropDownList using “isInteraction” argument in the select event of DropDownList.
If the value of “isInteraction” is true , then the item has been selected by user interaction. Otherwise it has been selected by properties or methods such as “selectItemByText”, “selectItemByValue” or “selectItemByIndices” in the DropDownList.
Initialize the DropDownList as follows
HTML
<div class="ctrllabel">Select a car</div> <input type="text" id="selectCar" /> <div id="carsList"> <ul> <li>Audi A4</li> <li>Audi A5</li> <li>Audi A6</li> <li>Audi A7</li> <li>Audi A8</li> </ul>
</div> <button id="button21">Select</button> var target; $(function () { target = $('#selectCar').ejDropDownList({ targetID: "carsList", width: "150px", select: "onSelect" }).data("ejDropDownList");
$("#button21").ejButton({ showRoundedCorner: true, size: "mini", click: "onClick" }); }); |
Upon selecting the items in the DropDownList, the client side event “select” will be triggered, in that check whether the value of isInteraction argument is true or not. If the value is true, the item has been selected by user(selected through the mouse hover).
Javascript
function onSelect(args) {
if (args.isInteraction) alert("The item " + args.value + " has been selected by user"); else alert("The item " + args.value + " has been selected programmatically"); }
function onClick(args) { target.selectItemByValue("Audi A7"); } |