validate验证jquery chosen相关问题

validate对jquery chosen-select无法验证,需要在validate加入

ignore: ":hidden:not(select)"

加入后可以成功校验,但是错误信息显示在select框上面

 

解决此问题是加入

errorPlacement
$("#form-add").validate({
    ignore: ":hidden:not(select)",
    rules: {
        id: {
            required: true
        }
    },
    messages: {
        id: {
            required: "请选择关联的数据字典"
        }
    },
    errorPlacement:function (error, element) {
        error.appendTo(element.parent());
    }
});

加上之后,错误信息显示在下面

 

想选择成功后 立刻清除错误信息,可以加入change事件

$(function() {
    $(".chosen-select").chosen({width: '95%',search_contains: true,no_results_text: "无对应数据..."});

    $(".chosen-select").change(function () {
        $(this).valid();
    })
});

 


 

posted @ 2019-01-10 16:00  秦悦空  阅读(566)  评论(0编辑  收藏  举报