Lijin Durairaj
Lijin Durairaj

Reputation: 5232

How to validate Kendo Dropdownlist using jQuery validate

I have normal razor as well as kendo controls in my form, i am facing some problem while trying to validate kendo dropdownlist using jquery validate plugin. The below is my code.

 @(Html.Kendo().DropDownList()
          .Name("color")
          .DataTextField("Text")
          .DataValueField("Value")
          .BindTo(new List<SelectListItem>() {
             new SelectListItem() {
                  Text = "Select Value",
                  Value = ""
              }, new SelectListItem() {
                  Text = "Black",
                  Value = "2"
              },
              new SelectListItem() {
                  Text = "Orange",
                  Value = "3"
              },
              new SelectListItem() {
                  Text = "Grey",
                  Value = "4"
              }
          }).Value("")
          .HtmlAttributes(new { style = "width: 100%" })
    )
    <input type="submit" value="Submit" />

now i have used my jquery validate like this

$(document).ready(function () {
        $("#dropDownForm").validate({
            rules: {
                color: "required"
            },
            highlight: function (element) {
                alert('highlight');
            },
            unhighlight: function (element) {
                alert('unhighlight');
            },
            errorPlacement: function (error, element) {
                return false;
            },
            debug: true
        });
    });

but i am not able to validate the dropdown list and both highlight and unhighlight event of jquery validate plugin is not getting called. Any help is appreciated. Thank you

Upvotes: 3

Views: 5611

Answers (1)

Vijai
Vijai

Reputation: 2509

Following is recommended

Put $.validator.setDefaults({ ignore: '' }); not inside $(document).ready

jQuery Validate - Enable validation for hidden fields

http://www.telerik.com/forums/mvc-client-validation-not-working

Upvotes: 3

Related Questions