How to use Twitter Bootstrap popovers for jQuery validation notifications?

后端 未结 16 1698
无人共我
无人共我 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:30

    Many thanks for the heads up! Here is my version for Bootstrap but with Tooltips. In my opinion it's more elegant than popovers. I know the question was for popovers so please do not vote down for this reason. Maybe somebody will like it this way. I love when I'm searching for something and I found new ideas on Stackoverflow. Note: no markup on form is necessary.

        $('#LoginForm').validate({
            rules: {
                password: {
                    required: true,
                    minlength: 6
                },
    
                email_address: {
                    required: true,
                    email: true
                }
            },
            messages: {
                password: {
                    required: "Password is required",
                    minlength: "Minimum length is 6 characters"
                },
                email_address: {
                    required: "Email address is required",
                    email: "Email address is not valid"
                }
            },  
            submitHandler: function(form) {
                form.submit();
            },
    
            showErrors: function (errorMap, errorList) {
    
                $.each(this.successList, function (index, value) {
                    $('#'+value.id+'').tooltip('destroy');
                });
    
    
                $.each(errorList, function (index, value) {
    
                    $('#'+value.element.id+'').attr('title',value.message).tooltip({
                        placement: 'bottom',
                        trigger: 'manual',
                        delay: { show: 500, hide: 5000 }
                    }).tooltip('show');
    
                });
    
            }
    
        }); 
    

提交回复
热议问题