简体   繁体   English

Bootstrap Validator summernote字段不会重新验证

[英]Bootstrap Validator summernote field doesn't revalidate

I'm using the bootstrap validator plugin to valid my form client side and it seems to fail when revalidating a summernote textarea. 我正在使用bootstrap验证器插件来验证我的表单客户端,并且在重新验证summernote textarea时似乎失败了。 It validates the first time, but when the text is updated the validation doesn't update. 它第一次验证,但是当文本更新时,验证不会更新。

Here's the validation ( snipped out other validation fields ) 这是验证( 剪掉其他验证字段

function validateEditor() {
    // Revalidate the content when its value is changed by Summernote
    $('#application-form').bootstrapValidator('revalidateField', 'application'));
};

$('.application-form')
    .bootstrapValidator({
        excluded: [':disabled'],
        fields: {
            application: {
                validators: {
                    callback: {
                        message: 'Please do not leave this blank.',
                        callback: function(value, validator) {
                            var code = $('[name="application"]').code();
                            // <p><br></p> is code generated by Summernote for empty content
                            return (code !== '' && code !== '<p><br></p>');
                        }
                    }
                }
            }
        }
    }).on('success.form.bv', function(e) {

        e.preventDefault();
        console.log('Form successfully validated.');


    })
    .find('[name="application"]')
        .summernote({
            height: 400,
            onkeyup: function() {

                validateEditor(); // Revalidate form onkeyup

            },
            onpaste: function() {

                validateEditor(); // Revalidate form on paste

            },

        });

Here's the markup ( again snipped from other fields ) 这是标记( 再次从其他字段中剪切

<div class="form-group">        

    <textarea name="application"></textarea>

</div>

This is a huge issue because if the textarea is left blank the first time, the form can never be resubmitted since the validation doesn't update when the error is fixed by the user. 这是一个很大的问题,因为如果第一次将textarea留空,则永远不会重新提交表单,因为当用户修复错误时验证不会更新。

I had the same problem, but with FormValidation.io, which is a very similar plugin. 我有同样的问题,但使用FormValidation.io,这是一个非常相似的插件。

Solution : My textarea had the required attribute. 解决方案 :我的textarea具有required属性。 I removed it and bam, problem solved. 删除了它 ,bam,问题解决了。

Now, I'm genuinely sorry if this isn't a direct solution to your problem, your code obviously doesn't have the required attribute, but I just thought I'd share with other people still, because this was driving me nuts for hours and this was the most relevant post about this problem on here. 现在,我真的很抱歉,如果这不是你问题的直接解决方案,你的代码显然没有required属性,但我只是觉得我还会与其他人分享,因为这让我感到疯狂小时,这是关于这个问题的最相关的帖子。

That is all. 就这些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM