How to use Twitter Bootstrap popovers for jQuery validation notifications?

后端 未结 16 1695
无人共我
无人共我 2020-11-30 16:49

I can make popovers appear using bootstrap easily enough, and I can also do validations using the standard jQuery validation plugin or the jQuery validation engine, but I ca

16条回答
  •  我在风中等你
    2020-11-30 17:33

    Here is an update to Kenny Meyer's excellent answer above. There were a couple of issues that prevented it from working for me, which I have addressed in this snippet:

    showErrors: function (errorMap, errorList) {
            $.each(this.successList, function (index, element) {
                return $(element).popover("destroy");
            });
    
            $.each(errorList, function (index, error) {
                var ele = $(error.element); //Instead of referencing the popover directly, I use the element that is the target for the popover
    
                ele.popover({
                        trigger: "manual",
                        placement: "top",
                        content: function(){ //use a function to assign the error message to content
                            return error.message
                        },
                        template: '

    ' }); //bs.popover must be used, not just popover ele.data("bs.popover").options.content = error.message; return $(error.element).popover("show"); }); }

提交回复
热议问题