as in the title, how can I prevent duplicates between 2 lists. I am trying to stop duplicates in the #selected list. I suspect its done in the receive event but i am not having any luck.
    $(function () {
    $("#options").sortable({
        connectWith: $("#selected"),
        helper: 'original',
        revert: true,
        tolerance: "pointer",
    });
    $("#selected").sortable({
        connectWith: $("#options"),
        helper: 'original',
        receive: function (event, ui) {            
        },
    });
    $("#options,#selected").disableSelection();
    $("#SkillGroups").change(function () {
        $.ajax({
            type: "POST",
            url: "/Contractor/Contractor/GetSkillsBySkillGroup",
            data: { skillGroupId: $("#SkillGroups").val() },
            success: function (result) {
                $loadList(result);
            }
        })
    });
});
                Finally worked it out. A bit obvious when you see the solution. There are probably other ways to do this as well.
 $("#selected").sortable({
        connectWith: $("#options"),
        helper: 'original',
        receive: function (event, ui) {
            var identicalItemCount  = $("#selected").children('li:contains(' + ui.item.text() + ')').length;
            alert(identicalItemCount);
            if (identicalItemCount > 1) {
                alert("Ahem.... we have a duplicate!!");
                $("#selected").children('li:contains(' + ui.item.text() + ')').first().remove();
            }
        },
    });
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With