jQuery - validate kendo dropdownlist with display:none style

会有一股神秘感。 提交于 2019-12-11 11:41:06

问题


In my view I have a kendo dropdownlist. I´ve implement jQuery validation inserting these scripts in the view:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

I've set the property as Required in the entity and all I need to perform the validation.

Model:

[Required(ErrorMessage = "Campo Tipo de Llenado es necesario")]
        public int TipoLlenado { get; set; }

View:

@(Html.Kendo()
    .DropDownListFor(model => model.pedidoGranelAutoEs.TipoLlenado)
    .BindTo(new SelectList(cmbTipoLlenado.Select(s => new { Key = s.IdDatoMaestro, Value = s.ValorPortal }), "Key", "Value"))
    .Events(events =>
    {
        events.Select("selectTipoLlenado");                         
    })
    .OptionLabel(Idioma.Shared.Pedidos_SeleccioneOpcion)
    )
@Html.ValidationMessageFor(model => model.pedidoGranelAutoEs.TipoLlenado)

The thing is that if I inspect the web with Chrome and remove the "display:none" style from the input generated by the kendo DropDownList (using Razor), and then press the Submit button the validation works fine.

I've tried the following solutions without result:

$(document).ready(function () {
        $('#formu').validate({
            ignore: []
        });
}

OR

$(document).ready(function () {
        $('#formu').validate({
            ignore: ':hidden'
        });
}

OR

$.validator.setDefaults({ ignore: []});

OR

$.validator.setDefaults({ ignore: ':hidden' });

Any advise??

Thanks in advance!!


回答1:


I've found the mistake. It was that I have to write the line:

$.validator.setDefaults({
        ignore: []
    });

outside of $(document).ready(function () {...}



来源:https://stackoverflow.com/questions/22476862/jquery-validate-kendo-dropdownlist-with-displaynone-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!