This is a migrated thread and some comments may be shown as answers.

Validate SelectedValue

1 Answer 60 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Neelima
Top achievements
Rank 1
Neelima asked on 28 Feb 2012, 11:54 PM
I'm using customValidator to validate the selected item of the ComboBox. This ComboBox has LoadonDemand enabled.  'validateCombo' code works fine when the selectedIndex is changed. After selecting an item, when a button on the same page is clicked validation doesnt work since there are no items in the ComboBox. How do I make it to work on button click event.

Appreciate your help!!

<telerik:RadComboBox runat="server" ID="rcbClients" Height="100px" EnableLoadOnDemand="true"
                                    ShowMoreResultsBox="true" EnableVirtualScrolling="true" AllowCustomText="false"
                                    EmptyMessage="Type lastname ...">
                                    <WebServiceSettings Path="Service1.svc" Method="LoadClients" />
                                </telerik:RadComboBox>
                                 
                                <asp:CustomValidator ID="cvClients" runat="server" ClientValidationFunction="validateCombo" SetFocusOnError="true"
                                    ErrorMessage="Please select a client from Dropdown" ControlToValidate = "rcbClients" >*
                                </asp:CustomValidator>

function validateCombo(source, args) {
    args.IsValid = false;
    var combo = $find(source.controltovalidate);
    var text = combo.get_text();
    var value = combo.get_value();
    if (text.length < 1) {
        args.IsValid = false;
    }
    else
    { var node = combo.findItemByText(text);
        if (node) {
             value = node.get_value();
 
 
            if (value.length > 0) {
                args.IsValid = true;
            }
        }
 
        else {
            args.IsValid = false;
        }
    }
}
 

1 Answer, 1 is accepted

Sort by
0
Neelima
Top achievements
Rank 1
answered on 01 Mar 2012, 06:32 PM
I solved this issue
function validateCombo(source, args) {
      args.IsValid = false;
      var combo = $find(source.controltovalidate);
      var selectedItem = combo.get_selectedItem();
      if (selectedItem) {
          var value = selectedItem.get_value();
          if (value > 0) {
              args.IsValid = true;
          }
      }
  }

Tags
ComboBox
Asked by
Neelima
Top achievements
Rank 1
Answers by
Neelima
Top achievements
Rank 1
Share this question
or