【问题标题】:How to validate both email using bootstrapValidator (identical)如何使用 bootstrapValidator 验证两封电子邮件(相同)
【发布时间】:2017-10-15 08:19:48
【问题描述】:

我正在使用 bootstrapValidator(相同)检查两封电子邮件是否相同,它工作正常,但我希望在同一行中显示错误消息,现在它们在两行中。见这里https://screenshots.firefox.com/abfJ97LEjpAncVoW/localhost。我尝试了很多方法并在谷歌中找到但没有得到任何解决方案。以下是我的验证码:

$('#formid').bootstrapValidator({

        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-alert',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            firstmail: {
                validators: {
                    notEmpty: {
                        message: 'The email address is required and can\'t be empty'
                    },
                     emailAddress: {
                        message: 'The input is not a valid email address'
                    },
                    identical: {
                        field: '2ndmail',
                        message: 'The email and its confirm are not the same'
                    }
                }
            },
            2ndmail: {
                validators: {
                    notEmpty: {
                        message: 'The email address is required and can\'t be empty'
                    },
                     emailAddress: {
                        message: 'The input is not a valid email address'
                    },
                    identical: {
                        field: 'firstmail',
                        message: 'The email and its confirm are not the same'
                    }
                }
            },
            },

    })

【问题讨论】:

    标签: bootstrapvalidator


    【解决方案1】:

    以下代码解决了我的问题,我已将其添加到此 $('#formId').bootstrapValidator({.....});

    $('#formid').bootstrapValidator({
    
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-alert',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        firstmail: {
            validators: {
                notEmpty: {
                    message: 'The email address is required and can\'t be empty'
                },
                 emailAddress: {
                    message: 'The input is not a valid email address'
                },
                identical: {
                    field: '2ndmail',
                    message: 'The email and its confirm are not the same'
                }
            }
        },
        2ndmail: {
            validators: {
                notEmpty: {
                    message: 'The email address is required and can\'t be empty'
                },
                 emailAddress: {
                    message: 'The input is not a valid email address'
                },
                identical: {
                    field: 'firstmail',
                    message: 'The email and its confirm are not the same'
                }
            }
        },
        },
    
    })
    
    .on('error.validator.bv', function(e, data) {
    // $(e.target)    --> The field element
    // data.bv        --> The BootstrapValidator instance
    // data.field     --> The field name
    // data.element   --> The field element
    // data.validator --> The current validator name
    
    data.element
        .data('bv.messages')
        // Hide all the messages
        .find('.help-block[data-bv-for="' + data.field + '"]').hide()
        // Show only message associated with current validator
        .filter('[data-bv-validator="' + data.validator + '"]').show();
    });
    

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 2018-02-15
      • 2021-12-18
      • 2014-05-28
      • 2019-07-05
      • 1970-01-01
      • 2017-11-09
      • 2012-04-04
      • 1970-01-01
      相关资源
      最近更新 更多