1

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.

jQuery - validate kendo dropdownlist with display:none style

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!!

javiazo
  • 1,892
  • 4
  • 26
  • 41

1 Answers1

3

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

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

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

javiazo
  • 1,892
  • 4
  • 26
  • 41
  • I'll mark it as a solution in 2 days (when stackoverflow let me ;)) – javiazo Mar 18 '14 at 10:51
  • Very strange solution somehow unique to you, as [it's been proven through jsFiddle demonstrations](http://stackoverflow.com/a/8565769/594235) that it makes no difference whether the setting is in or out of the DOM ready event handler. It's either set or it isn't... the plugin either ignores hidden fields or it doesn't. How exactly does the DOM ready event handler make any difference in this case? – Sparky Mar 18 '14 at 16:27
  • I had it working inside DOM Ready and it suddenly broke and putting it outside now works! – Smith Aug 15 '16 at 21:18