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

ComboBox ClientSide Validation

3 Answers 140 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
DK
Top achievements
Rank 2
DK asked on 11 Aug 2009, 04:58 AM
hi
I have radcombobox.
now when my page loads some values are selected in the combobox.
now i m checking client side that if  something is selected in the combobox then i disable a radtextbox and if nothing is selected then i enable the same.

now i have added a custom validator on another combobox which is dependent on the first combobox.
if first combobox is not selected then no validation and if the first combobox have selected value and second combo have not any selected value then i show error.

i used
function validate(sender,args)
{
args>IsValid=true;
cmb1=$find("<%= cmb1ID.ClientID%>");

cmb2=$find("<%= cmb2ID.ClientID%>");

if(cmb1.get_selectedIndex()>0 && cmb2.get_selectedIndex()<0) // I have also used cmb1.get_value() and cmb1.get_selectedItem()
{
args.IsValid=false;
return
}

and the first item in my combobox is null and second item is "Please Select" and the remaining items are there.
alnd aloow custom text is true.

please help me to validate the above problem
its urgent.
}
}

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 Aug 2009, 04:04 PM
Hello DK,

We are not sure what the exact scenario is. Could you please open a support ticket and send us a sample page which shows the issues you are experiencing? Thanks.

Regards,
Albert,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Tim
Top achievements
Rank 1
answered on 20 May 2010, 02:56 PM
Was a solution found to this because I have the same problem, the first item is returned as null and subsequent records are numbered from index 0.  The problem is the selecteditem even later if the first one is picked is null and therefore useless.

I want to use a common javascript code to validate from the custom validators and ensure the page is valid before submission

Code Below
<script type="text/javascript">  
 
        function ReqFieldValidationCBox(source, arguments) {              
            var Cbox = $find(source.controltovalidate);  
            if (Cbox) {  
                //alert(Cbox.get_selectedIndex());  
                if (Cbox.get_selectedIndex() == null || Cbox.get_selectedIndex() == "") {  
                    Cbox._element.style.border = "solid 1px red";  
                    arguments.IsValid = false;  
                }  
                else {  
                    Cbox._element.style.border = "";  
                    arguments.IsValid = true;  
                }  
            }  
        }  
 
        function clientSelectedIndexChange(sender, args) {  
            Page_ClientValidate();  
        }  
      
 </script> 
   
   
 <asp:CustomValidator ID="cvLicensest" runat="server" ControlToValidate="txtStockCode" ValidateEmptyText="true"  ClientValidationFunction="ReqFieldValidationCBox" CssClass="error" EnableClientScript="true" Display="Dynamic"  /> 
   
   
 <telerik:RadComboBox  
        ID="txtStockCode" runat="server" 
        Width="250px" Height="140px"   
        EmptyMessage="Enter or Pick Stock Code" 
        MarkFirstMatch="true"   
        EnableLoadOnDemand="true" ShowMoreResultsBox="true"   
        Culture="English (United Kingdom)">  
        OnClientSelectedIndexChanged="clientSelectedIndexChange" 
        OnClientTextChange="clientSelectedIndexChange"   
    <WebServiceSettings Path="~/services/SuppliesSvc.svc"   
    Method="LoadStockData" /> 
</telerik:RadComboBox> 

I'm sure this is not a bug but a feature I don't understand but need a way around it. 

Once the validation is work for forcing a selection the next step is to make sure they haven't just got Custom text because it doesn't seem to restrict input the nodes loaded. 

Thanks in advance.

Tim
0
Kalina
Telerik team
answered on 25 May 2010, 05:47 PM
Hi Tim,

I made a small sample page using the code snippets that you sent to us and I can say that on my side your code works properly.

When you use Load-On-Demand feature, the RadComboBox SelectedItem is not persisted server-side, however you can use SelectedValue and Text server-side properties. Please find more details at this help article.


All the best,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox
Asked by
DK
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Tim
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or