【问题标题】:How to validate Kendo Dropdownlist using jQuery validate如何使用 jQuery validate 验证 Kendo Dropdownlist
【发布时间】:2016-08-02 19:55:57
【问题描述】:

我的表单中有普通剃须刀和剑道控件,我在尝试使用 jquery validate 插件验证剑道下拉列表时遇到了一些问题。 以下是我的代码。

 @(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" />

现在我已经像这样使用我的 jquery 验证了

$(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
        });
    });

但我无法验证下拉列表,并且 jquery validate 插件的突出显示和取消突出显示事件都没有被调用。 任何帮助表示赞赏。 谢谢

【问题讨论】:

  • 既然您已经在使用 Kendo UI,为什么不能使用 Kendo 验证器:demos.telerik.com/kendo-ui/validator/index
  • @Vijai 我不想使用剑道验证器的原因是因为我有很多控件是剃须刀控件,并且我的项目中要求仅使用剑道控件进行下拉和剑道可拖动...你能帮我了解如何使用 jQuery 验证器验证剑道下拉菜单,正如我在上面的问题中明确建议的那样

标签: kendo-ui jquery-validate kendo-asp.net-mvc


【解决方案1】:

以下推荐

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

【讨论】:

  • 这将破坏带有隐藏输入的表单。相反,使用$.validator.setDefaults({ ignore: ":hidden:not(span.k-dropdown:visible &gt; input)" }); 仅忽略隐藏的输入,这些输入不属于仍然可见的剑道下拉菜单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多