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

RadComboBox + RequiredFieldValidator How to make it validate on tab

1 Answer 365 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Carlo
Top achievements
Rank 1
Carlo asked on 06 Oct 2014, 04:49 PM
With the Microsoft Validator controls (RequiredFieldValidator in this case) the typical behavior is for validation logic to run when you tab out of the field, or on submit. 

I have noticed with RadComboBox this is **not** the case, even in your own online demo. Rather, with RCB validation *only* occurs when you attempt to submit. Is there any way to force this to validate on tab out? Typically the field would look something like this in code:

1.<telerik:RadComboBox ID="rcbPatientMaritalStatus" EmptyMessage="Start typing marital status or select one" MarkFirstMatch="true" TabIndex="8" Width="160" runat="server">
2.    <Items>
3.        <telerik:RadComboBoxItem Text="Single" Value="Single" />
4.        <telerik:RadComboBoxItem Text="Married" Value="Married" />
5.        <telerik:RadComboBoxItem Text="Other" Value="Other" />
6.    </Items>
7.</telerik:RadComboBox>
1.<asp:RequiredFieldValidator ID="rfvPatientMaritalStatus" ControlToValidate="rcbPatientMaritalStatus" ErrorMessage="Marital Status Required" Display="None" Visible="false" runat="server" />

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 08 Oct 2014, 08:37 AM
Hello Carlo,

First, I would suggest you to remove the Visible="false" settings of the RequiredFieldValidator, since in such a manner, the validator is not rendered on the page, and the desired behavior could not be achieved.

As for the desired functionality, you could use the OnClientBlur client-side event of the RadComboBox and use the  Page_ClientValidate() function, which will trigger all validators on the page. In order to trigger the validation only on the RadComboBox, you would need to relate the control and its validator, using ValidationGroup. Thus, you will be able to point which validation group to trigger in the Page_ClientValidate(). Below you could find the modified code snippet, demonstrating how to achieve the desired functionality :

// markup
<telerik:RadComboBox ID="rcbPatientMaritalStatus" EmptyMessage="Start typing marital status or select one"
    MarkFirstMatch="true" TabIndex="8" Width="160" runat="server" OnClientBlur="OnClientBlur" ValidationGroup="test">
    <Items>
        <telerik:RadComboBoxItem Text="Single" Value="Single" />
        <telerik:RadComboBoxItem Text="Married" Value="Married" />
        <telerik:RadComboBoxItem Text="Other" Value="Other" />
    </Items>
</telerik:RadComboBox>
 
<telerik:RadButton runat="server" OnCheckedChanged="Unnamed_CheckedChanged" ID="btn1"></telerik:RadButton>
 
<asp:RequiredFieldValidator ID="rfvPatientMaritalStatus" ControlToValidate="rcbPatientMaritalStatus"
    ErrorMessage="Marital Status Required" runat="server" Display="Dynamic" ValidationGroup="test" />

//javascipt
<script type="text/javascript">
        function OnClientBlur(sender, args) {
            Page_ClientValidate("test")
        }
    </script>



Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Carlo
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or