Client Side Validation - Need JavaScript Help

2 posts, 0 answers
  1. David
    David avatar
    1 posts
    Member since:
    Mar 2013

    Posted 18 Jun 2013 Link to this post

     Hi Guys,
     I haven't had the need to use much please forgive my ignorance.
     Im trying to write some client-side validation code.
     The premise is that each listbox item hold a delimited value that contains a ProductId and other ProductIds it cannot coexist with.
     For example value=1,4,6,8.  This is intrepreted that the ProductId of this item =1 and it cannot be added to any list box which already has Products 4,6 or 8 in it.
     I have successfully done this server side with the following code and I am trying to reproduce client-side with javascript.  Any help would be appreciated.

    Private Sub RadListBoxDestination_Transferring(sender As Object, e As Telerik.Web.UI.RadListBoxTransferringEventArgs) Handles RadListBoxDestination.Transferring
        Dim aryNoCoExist As Array
        Dim i As Integer
        Dim Product As Integer
        Dim Cancel As Boolean = False
        Dim BoxItem As Telerik.Web.UI.RadListBoxItem
        Dim NoCoExist As String = ""
        Me.ErrorLabel.Text = ""
        If RadListBoxDestination.Items.Count > 0 Then
            Product = GetProductId(e.Items(0).Value) 'GetProductId returns the first delimited string  item
            For Each BoxItem In RadListBoxDestination.Items
                If Len(NoCoExist) Then
                    NoCoExist = NoCoExist & "," & GetNoCoExist(BoxItem.Value) 'GetNoCoExist returns the remaining delimited string minus the first item
                    NoCoExist = GetNoCoExist(BoxItem.Value)
                End If
            aryNoCoExist = Split(NoCoExist, ",")
            For i = 0 To aryNoCoExist.GetUpperBound(0)
                If Product = aryNoCoExist(i) Then
                    Cancel = True
                    Me.ErrorLabel.Text = "Product Not Compatible with Existing Selections"
                End If
            e.Cancel = Cancel
        End If
    End Sub
        My Listbox Definition: 






    <telerik:RadListBox runat="server" ID="RadListBoxSource" Height="200px" Width="300px" AllowTransfer="true" TransferToID="RadListBoxDestination"
                            AllowTransferOnDoubleClick="True"  EnableDragAndDrop="True">
                            <ButtonSettings TransferButtons="Common" ShowDelete="False" ShowReorder="False" ShowTransferAll="False"></ButtonSettings>
                        <telerik:RadListBox ID="RadListBoxDestination" runat="server" Height="200px" Width="300px" AllowTransfer="true" TransferToID="RadListBoxSource"
                            AllowTransferOnDoubleClick="True"  EnableDragAndDrop="True" OnClientTransferring="onTransferring">
                            <ButtonSettings TransferButtons="Common" ShowTransfer="false" ShowDelete="False" ShowReorder="False" ShowTransferAll="False"></ButtonSettings>





  2. Kate
    Kate avatar
    1898 posts

    Posted 21 Jun 2013 Link to this post

    Hi David,

    You can use the OnClientTransferring client-side function and implement the desired logic. For example in this help article you can find an instance demonstrating how to loop through all of the ListBoxItems so you can implement the desired check.

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top