jQuery picklist deselect an item programmatically

389 views Asked by At

I have a picklist, based on a checkbox, I wanted to restrict the picklist selection. I wanted to remove those items from the targetList or restrict it being populated there.

$("#source-catalogue").pickList({
sourceListLabel : "Source Catalogue",
targetListLabel : "Source Fields",
addAllLabel : "â–ºI",
addLabel : "â–º",
removeAllLabel : "Iâ—„",
removeLabel : "â—„",
sortItems : false,
beforeAdd: function(){
if(ConfigGlobals.reOrderFlag){
    tmpList = $('#source-container ul.pickList_targetList li');
    alert("Please uncheck mycheckbox and then try");
}
},
afterAdd: function(){
    if(ConfigGlobals.reOrderFlag){
        curLen = $('#source-container ul.pickList_targetList li').length
        diff = curLen - tmpList.length
            // remove the selection
    }
},
1

There are 1 answers

0
lima On

I have done this as below.

On the afterAdd callback, for each item, i have added these calls.

$(item).trigger('click');
$('#source-container .pickList_remove').trigger('click');

This removed the item from selection and added back to the list.