4

I have been running jquery validation and summernote side by side for a while now successfully.

it was working and now I am getting an error on form.valid(). The note field doesn't need to be validated.

I have stripped my code down to the bare minimum, and whittled down the Ignore settings - if I remove the ignore settings it works, if I have ignore settings, it breaks, with a "validator is undefined" error

I have set up a fiddle so you can see it working and not working, it's currently set not to work

http://jsfiddle.net/JGuymer/83q0r21s/22/

<form id="form">   
<textarea id="textarea"></textarea>
<a id="clickme" href="#">click Me</a>
</form>

JQuery:

$(document).ready(function() {
    $("#textarea").summernote();
    //uncomment to work
    //$('#form').validate();       
    //uncomment to fail
    $('#form').validate({ignore:[]})     
    $("#clickme").click(function(){      
        validate();         
        return false;
    })
});

function validate() {
 if ($('#form').valid()) {
 alert('valid');
 }
}

Any ideas would be appreciated

Thanks James

4

3 回答 3

3

我有一个类似的问题。

首先,您可以设置jquery.validate忽略隐藏字段(IIRC,summernote 有很多),除了您要验证的那些:

$.validator.setDefaults({ ignore: ":hidden:not(.class-of-hidden-field-i-want-to-validate-1, class-of-hidden-field-i-want-to-validate-2, class-of-hidden-field-i-want-to-validate-3...) }); 

那为我修好了。

此外,每当我与模式对话框交互以添加链接(summernote v0.5.10)时,我得到了

Uncaught TypeError: Cannot read property 'settings' of `undefined`

jquery.validate.js:360

看着summernote.js我可以他们有:

var tplDialog = function (className, title, body, footer) {
        return '<div class="' + className + ' modal" aria-hidden="false">' +
                 '<div class="modal-dialog">' +
                   '<div class="modal-content">' +
                     (title ?
                     '<div class="modal-header">' +
                       '<button type="button" class="close" aria-hidden="true" tabindex="-1">&times;</button>' +
                       '<h4 class="modal-title">' + title + '</h4>' +
                     '</div>' : ''
                     ) +
                     '<form class="note-modal-form">' + // ERROR CAUSE
                       '<div class="modal-body">' +
                         '<div class="row-fluid">' + body + '</div>' +
                       '</div>' +
                       (footer ?
                       '<div class="modal-footer">' + footer + '</div>' : ''
                       ) +
                     '</form>' + // ERROR CAUSE
                   '</div>' +
                 '</div>' +
               '</div>';
    };

我的(临时)修复在我form用. 也许我遗漏了一些东西,但无论如何我都没有真正看到将其作为一种形式的意义。div// ERROR CAUSE

不建议更改此代码(您可能希望更新到较新的版本,从而丢失您的更改...),但在他们解决之前,这是一个足够好的修复。

于 2014-11-07T13:30:18.853 回答
2

我有同样的问题。我将问题追溯到名为“note-modal-form”的子表单。为了解决这个问题,我在初始化部分添加了以下内容:

var validateform = function () {

    $('.note-modal-form').each( function() { $(this).validate({}) });
...     
于 2014-12-05T12:11:53.343 回答
0

我有同样的问题,原来summernote有没有名字的隐藏字段。验证失败,您可以忽略这些字段,也可以像我一样转到summernote js js代码并添加一个名称。希望这可以帮助。

输入字段用于弹出summernote的模态,用于添加ur。在此处输入图像描述

于 2017-09-09T04:16:34.023 回答