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

jquery required validation not working for editable radcombobox

1 Answer 105 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Pushkar
Top achievements
Rank 2
Pushkar asked on 22 Dec 2011, 03:56 PM
I am using Editable radcombobox. I need to use jquery validation(not asp required field validator) for this. But this is not working properly.
When I select a item from drop down, the validation does not work immediately. As soon as I click out side(focus lost from dropdown), It works. Please give me any solution for this issue. Thanks

$(document).ready(
function() {

        $.validator.addMethod("selectFirst", function(value, element) {
            if (element.value == 'Please Select...')
                return false;
            else
                return true;
        }, "Error Message");

        $("#<%=radComboBox.ClientID%>_Input").addClass("selectFirst");
        $("#" + document.forms[0].id).validate();
    });

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 27 Dec 2011, 09:47 AM
Hello Pushkar,

You can try using Custom Validator. Here is an example:
function validationFunction(source, args)
{
    if (args.Value == " - Select a City - ")
    {
        args.IsValid = false;
    } else
    {
        args.IsValid = true;
    }
}
<telerik:RadComboBox runat="server" ID="RadComboBox1">
    <Items>
        <telerik:RadComboBoxItem Text=" - Select a City - " Value="SelectCity" />
        <telerik:RadComboBoxItem Text="Paris" Value="Paris" />
        <telerik:RadComboBoxItem Text="Rome" Value="Rome" />
        <telerik:RadComboBoxItem Text="London" Value="London" />
    </Items>
</telerik:RadComboBox>
<asp:Button ID="Button1" Text="Validate" runat="server" />
<asp:CustomValidator ID="CustomValidator1" ErrorMessage='You must select a city!'
    ControlToValidate="RadComboBox1" ValidateEmptyText="true" runat="server" ClientValidationFunction="validationFunction"
    CssClass="validationClass" />

I hope this helps.

Regards,
Ivana
the Telerik team
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 their blog feed now
Tags
ComboBox
Asked by
Pushkar
Top achievements
Rank 2
Answers by
Ivana
Telerik team
Share this question
or