错误放置,Select2 [英] Error placement, Select2

查看:170
本文介绍了错误放置,Select2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我保存包含一个或多个select2的表单时,我遇到了 select2 错误放置的问题.

这里是我所拥有的:我有一些带有一些强制性select2输入的表单,它们可以很好地显示jQuery Validate的错误,但是我想要的是html在保存表单时跳转到带有错误的select2的html.目前,提交处理程序可以跳到除选择器之外的任何其他元素上.

解决方案

我最终覆盖了无效的处理程序,并调用了select2的ID:

 invalidHandler: function(form, validator) {
    var errors = validator.numberOfInvalids();
    if (errors) {
        if($(validator.errorList[0].element).is(":visible"))
        {
            $('html, body').animate({
                scrollTop: $(validator.errorList[0].element).offset().top
            }, 100);
        }
        else
        {
            $('html, body').animate({
                scrollTop: $("#s2id_" + $(validator.errorList[0].element).attr("id")).offset().top
            }, 100);
        }
    }
}
 

I have a problem with select2 error placement when I save a form containing one or many select2.

Here is what I have: I have some Forms with some mandatory select2 inputs and they work fine showing the error with jQuery Validate but whatI want is the html to jump to the select2 with the error when I save the form. Currently the submit handler jumps just fine to any other element except the selectors.

解决方案

I ended up overwriting the invalid handler and call the id of the select2:

invalidHandler: function(form, validator) {
    var errors = validator.numberOfInvalids();
    if (errors) {
        if($(validator.errorList[0].element).is(":visible"))
        {
            $('html, body').animate({
                scrollTop: $(validator.errorList[0].element).offset().top
            }, 100);
        }
        else
        {
            $('html, body').animate({
                scrollTop: $("#s2id_" + $(validator.errorList[0].element).attr("id")).offset().top
            }, 100);
        }
    }
}

这篇关于错误放置,Select2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆