Not getting validation message for @Html.DropDownListFor() once Chosen jquery is used

拜拜、爱过 提交于 2019-11-28 13:54:29

Restating my brief comment as an answer. :-)

To get the validation messages, I use the same approach Joseph mentions, though I use an HTML class for those selects that I am using with Chosen. For example:

validator.settings.ignore = ":hidden:not(.select-chosen)";

To clear the validation message when a value is selected, you need to attach an event listener for "change" events and explicitly force revalidation of the select. So for example, assuming you have a variable select that references the select box:

select.on("change", function(evt, params) {
    $(evt.target).valid();
});

Chosen triggers those "change" events whenever it's value changes.

Solved after a lot of research...

$(document).ready(function () {
    var validator = $("#Your_form_id").data('validator');
    validator.settings.ignore = ":hidden:not(select)";
});

So aligning the above answers properly

 $(function () {
        var validator = $("#Your_form_id").data('validator');
        validator.settings.ignore = ":hidden:not(.chosen-select)";
        $(".chosen-select").chosen();
        $("#Your_dropdown_id").change(function (evt, params) {
            $(evt.target).valid();
        })

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