I am trying to write a function that if a condition exists, it cancels the selection and provides an alert("something is wrong") to the user. This works; however, when the selection is cleared from the destination box, it no longer appears in the source box.
Here is html for Listbox:
<telerik:RadListBox RenderMode="Lightweight" runat="server" ID="boxSource" Height="350px" Width="250px"
AllowReorder="false"
AllowTransfer="true"
AllowTransferDuplicates="false"
SelectionMode="Multiple"
TransferMode="Move"
TransferToID="boxDestination">
<HeaderTemplate>
Available Fields
</HeaderTemplate>
</telerik:RadListBox>
<%-- Selected Fields --%>
<telerik:RadListBox RenderMode="Lightweight" runat="server" ID="boxDestination" Height="350px" Width="250px"
SelectionMode="Multiple"
AllowReorder="true">
<HeaderTemplate>
Zone Fields
</HeaderTemplate>
</telerik:RadListBox>
Here is jQuery:
var zoneNo = $("table.template td.active").attr("data-zone");
var listBox = $find("<%= boxDestination.ClientID %>");
//get current selected items
var items = listBox.get_items();
//store
if (items.get_count() > 0) {
if(zoneNo == undefined )
{
items.clear();
return alert("Please select a zone");
}
let itemsCopy = Object.assign({}, items);
$.data(listBox, zoneNo, itemsCopy);
}