jquery-validate的问题

时间:2014-03-28 17:33:04

标签: javascript jquery jquery-validate

我正在使用jQuery validate插件来验证表单。我在表单上验证的字段是“To”,“CC”,“Bcc”。

我在使用jquery-validate进行验证时遇到以下奇怪问题:

  1. jquery-validate不会仅验证第二个字段。它验证了第三个。 (我把cc与Bcc交换了现在Bcc排在第二位,它不会得到验证)。
  2. 在任何字段中输入一些文本并删除文本并点击“提交”,验证将无效。
  3. 我创建了一个JSfiddle,它有三个文本字段,似乎正在工作。 Example JSfiddle

    下面粘贴代码:

      App.CreateSendEmailDialogForReports = function (title, reportUrl, from) {
    
    
            dialogOpts.open = function (event, ui) {
    
    
                $.validator.addMethod("multiemail", function (value, element) {
    
                    var emails = value.split(new RegExp("\\s*,\\s*", "gi"));
                    valid = true;
                    for (var i in emails) {
                        value = emails[i];
                        value = value.commaTrim().trim();
                        if (value.length == 0)
                            continue;
                        try {
                            valid = valid && $.validator.methods.email.call(this, value, element);
                        } catch (e) {
                            App.log(e.toString());
                        }
    
                    }
                    return valid;
                }, 'One or more email addresses are invalid');
    
    
                $("#frmSendEmail", "#dvSendEmail").validate({
                      errorLabelContainer: "#msgBox",
                wrapper: "li",
                onfocusout: false,
                submitHandler: function (form) {
                    var $form = $(form);
                    //var url = GetPath($form.attr('action'));
                    var url = $form.attr('action');
                   // var tofield, fromfield, msgfield, urlfield, reportNamefield, ccfield, bccfield, subjectfield;
                    var tofield, fromfield, notesfield, urlfield, reportNamefield, ccfield, bccfield, subjectfield;
                    // get some values from elements on the page:
                    tofield = $form.find('#To').val();
    
                    ccfield = $form.find('#Cc').val();
                    bccfield = $form.find('#Bcc').val();
    
                    subjectfield = $form.find('#Subject').val() ;
    
                    fromfield = $form.find('#From').val();
    
                    //Send the data using post and put the results in a div                   
    
                    $.post(url, { To: tofield, Cc: ccfield, Bcc: bccfield, Subject: subjectfield, From: fromfield },
                        function (data) {
                            var content = document.createElement('h3').appendChild(document.createTextNode('<p>Email with link to <b>' + urlfield + '</b>' + ' was successfully sent!</p>'));
                            $("#frmSendEmail", "#dvSendEmail").empty().append(content.data);
                            setTimeout(function () { App.SendEmailReports.dialog("close"); }, 1000);
    
    
                        }
                        );
                },          
                    rules: {
                    "To": {                    
                        require_from_group: [1, ".reqrd"],
                        multiemail: true
                        },
                     "Cc": {
                         require_from_group: [1, ".reqrd"],
                         multiemail: true
            },
                     "Bcc": {
                         require_from_group: [1, ".reqrd"],
                         multiemail: true
                     }
                },
    
                groups: {
                    emailGroup: "To Cc Bcc"
                }
    
                });
    
            };
    
        }
    

0 个答案:

没有答案