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

Text vs Value field

4 Answers 64 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ben White
Top achievements
Rank 1
Ben White asked on 17 May 2010, 12:45 PM
Hi,

I have hit a ludicrous problem. Using regular asp.net controls, I can add a few items to a listbox and set the initial item to have:
Value=""
Text="Please select"

This means that error checking is very easy as I only have to check for an empty string to catch a required validator.

I am using a radcombo in conjunction will JQuery Validator and I need to be able to do the same otherwise I have no way of checking whether the user has selected an item. Currently the only way I can see how to do it is set the item to :
Value=""
Text=""

This is no good as I need to display the text "Please select"

Any help appreciated.

Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 May 2010, 01:14 PM
Hello Ben,

If you want to use RequiredFieldValidator for validating RadComboBox, then try changing the initial value of RequiredFieldValidator as "Please select" (same as the first RadComboBoxItem's text) and see whether it is working fine.

aspx:
 
<telerik:RadComboBox ID="cboSearchType" runat="server" Skin="Forest" Width="425px">   
        <Items>  
               <telerik:RadComboBoxItem runat="server" Selected="True" Text="Please Select" Value="-1" />  
               <telerik:RadComboBoxItem runat="server" Text="Customer Name" Value="1" />  
               <telerik:RadComboBoxItem runat="server" Text="Account Number" Value="2" />  
        </Items>  
</telerik:RadComboBox>  
  
<asp:RequiredFieldValidator InitialValue="Please Select" ControlToValidate="cboSearchType"    
                ValidationGroup="search" ID="RequiredFieldValidator8" runat="server" ErrorMessage="Required" /> 

Thanks,
Princy.
0
Ben White
Top achievements
Rank 1
answered on 17 May 2010, 01:43 PM
Hi,

Thanks for your reply.

As stated in my post I am using the radcombo with JQuery Validator. Ideally I want set a radcombo item and have its value = "" and it text="something"

Cheers
0
Accepted
Kalina
Telerik team
answered on 20 May 2010, 12:39 PM
Hello Ben White,

As I understand you use this JQuery validation  plug-in.

I prepared a small example for you to illustrate the approach of adding a "default" RadComboBoxItem as you describe in your post:
<script type="text/javascript">
 
      $(document).ready(function() {
       
                $("#commentForm").validate(
                    {  errorLabelContainer: "#messageBox",
                        wrapper: "li"}
                    );
 
                $(".rcbInput").rules("add", {
                        selectElement: true
                     
                });
                $(".rcbInput").validate();
 
            });
 
        jQuery.validator.addMethod('selectElement',
          function(value, element) {
              if (element.value == 'Please select') {
                  return false;
              }
              else return true;
          },
          "Please select item from RadComboBox"
           
        );
 
    </script>

<form runat="server" id="commentForm" method="get" action="">
   <div>
       <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
       </telerik:RadScriptManager>
       <ul id="messageBox">
       </ul>
       <telerik:RadComboBox ID="RadComboBox1" runat="server" >
           <Items>
               <telerik:RadComboBoxItem Text="Please select" Value="" />
               <telerik:RadComboBoxItem Text="1" Value="1" />
               <telerik:RadComboBoxItem Text="2" Value="2" />
           </Items>
       </telerik:RadComboBox>
       <input id="Submit1" type="submit" value="Submit" runat="server" />
   </div>
   </form>

Please note the additionally added custom validation method ("selectElement") that validates the RadComboBox input upon the text of the first (default) item.

As JQuery renders the error message as label next to the RadComboBox input element and this breaks the control output – I added an unordered list container (“messageBox”) to display the message in.

More details about JQuery validation you can find here.

Regards,
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.
0
Ben White
Top achievements
Rank 1
answered on 20 May 2010, 12:54 PM
Perfect - thank you so much for your help!
Tags
ComboBox
Asked by
Ben White
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ben White
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or