jQuery Validate Plugin ไม่ได้ตรวจสอบข้อกำหนดทั้งหมดในการส่ง

ฉันได้อ่านโพสต์อื่นๆ แล้วและไม่เข้าใจว่าทำไมช่องที่ต้องกรอกบางช่องของฉันจึงไม่ผ่านการตรวจสอบเมื่อส่ง ฉันกำลังช่วยฝั่งไคลเอ็นต์ในการตรวจสอบสคริปต์ของเขา และแบบฟอร์มนี้ถูกโพสต์ไปยังบุคคลอื่น บนเซิร์ฟเวอร์ของฉัน: http://alluringassets.com/caitlin/projects/validationscript/index.html. หากฉันมุ่งเน้นไปที่วันที่จัดงาน มันจะตรวจสอบข้อมูล แต่ถ้าฉันไม่เคยมุ่งเน้นไปที่ข้อมูลนั้นเลย และฉันคลิกส่ง โปรแกรมจะไม่ตรวจสอบสถานที่ ขนาดกลุ่ม วันที่จัดงาน แต่จะตรวจสอบฟิลด์ด้านบนสุด มีความคิดอะไรบ้าง?

$.validator.addMethod("groupMin", function(value) {
        return $("#00NG0000008iHKH").val() >= 6;
    }, 'Sorry, but we only handle groups of 6 or more.');

$.validator.addMethod("seoNO", function(value) {
        return $("#00NG0000008iHKg").match(/SEO/g);
    }, 'No thank you! We are not interested in Search Engine Optimization support.');

$.validator.setDefaults({
    //submitHandler: function() { 
        //form.submit();
        //alert("submitted!"); }
});

$().ready(function() { 
var validator = $("#detailRequestForm").bind("invalid-form.validate", function() {
            $("#summary").html("Your form contains " + validator.numberOfInvalids() + " errors. Please correct.");
        }).validate({
        rules: {
            firstname: "required",
            lastname: "required",
            email: {
                required: true,
                email: true
            },
            company: {
                required: true,
                minlength: 2
            },
            '00NG0000008iHK7': {//Program Location
                required: true,
                minlength: 2
            },
            '00NG0000008iHKH': //Group Size
                "groupMin",
            '00NG0000008iHKR': {//Event Date
                required: true,
                minlength: 3
            },
            '00NG0000008iHKg':"seoNO",
        },
        messages: {
            firstname: "Please enter your firstname",
            lastname: "Please enter your lastname",
            email: "Please enter a valid email address",
            company: "We do not serve private groups. Sorry, we can't help you.",
            '00NG0000008iHK7': //Program Location
            "Where will the program be located?",
            '00NG0000008iHKH':{//Group Size
                required:"Please enter the number of members in the group.",
            },
            '00NG0000008iHKR': {//Event Date
                required: "Please enter a date or TBA if you are unsure."
            },
            '00NG0000008iHKg': {//Comments
                //required: "Please enter any comments or questions you may have."
            }
        },
        errorElement: "em",
        errorContainer: $("#warning, #summary"),
        //highlight: function(label) {
            //$(label).removeClass("success").addClass('error');
        //},
        //success: function(label) {
                //label.text("ok!").empty().addClass("success");

            //}

    });
  });

person Caitlin Havener    schedule 27.11.2012    source แหล่งที่มา
comment
HTML ที่ไปพร้อมกับสิ่งนี้อยู่ที่ไหน?   -  person Sparky    schedule 27.11.2012


คำตอบ (2)


ฉันก็คิดออกทั้งหมดแล้ว หากใครสนใจผลงานดังต่อไปนี้

// JavaScript Document
//Script written by Caitlin Havener
//Utilizing jQuery validation plugin
//Visit sneakymommedia.com to hire me!
$.validator.addMethod("groupMin", function(value) {
        return $("#00NG0000008iHKH").val() >= 6;
    }, 'Sorry, but we only handle groups of 6 or more.');

    /*$.validator.addMethod("seoNO", function(value) {
            return $("#00NG0000008iHKg").match("/SEO/g");
        }, 'No thank you! We are not interested in Search Engine Optimization support.');*/

    $.validator.setDefaults({
        submitHandler: function() { 
            //form.submit();
            alert("submitted!"); }
});

$.validator.addMethod(
        "regex",
        function(value, element, regexp) {
            var re = new RegExp(regexp);
            return this.optional(element) || !re.test(value);
        },
        "No thank you! We are not interested in Search Engine Optimization support."
);


$().ready(function() { 
    var validator = $("#detailRequestForm").bind("invalid-form.validate", function() {
            $("#summary").html("Your form contains " + validator.numberOfInvalids() + " errors. Please correct.");
        }).validate({
        //debug: true,
        rules: {
            firstname: "required",
            lastname: "required",
            email: {
                required: true,
                email: true
            },
            company: {
                required: true,
                minlength: 2
            },
            '00NG0000008iHK7': {//Program Location
                required: true,
                minlength: 2
            },
            '00NG0000008iHKH': //Group Size
                "groupMin",
            '00NG0000008iHKR': {//Event Date
                required: true,
                minlength: 3
            },
            '00NG0000008iHKg':{
                //"seoNO",
                regex: / SEO |SEO| seo |seo|Search Engine Optimization | Search Engine Optimization |Search Engine Optimization/
            }
        },
        messages: {
            firstname: "Please enter your firstname",
            lastname: "Please enter your lastname",
            email: "Please enter a valid email address",
            company: "We do not serve private groups. Sorry, we can't help you.",
            '00NG0000008iHK7': //Program Location
            "Where will the program be located?",
            '00NG0000008iHKH':{//Group Size
                required:"Please enter the number of members in the group.",
            },
            '00NG0000008iHKR': {//Event Date
                required: "Please enter a date or TBA if you are unsure."
            },
            '00NG0000008iHKg': {//Comments
                //required: "Please enter any comments or questions you may have."
            }
        },
        errorElement: "em",
        errorContainer: $("#warning, #summary"),
        validClass: "success",
        focusCleanup: true,
        success: function(label) {
                label.text("ok!").addClass("success");
            }
    });

});
person Caitlin Havener    schedule 29.11.2012

รหัสไม่ควรขึ้นต้นด้วยตัวเลข เพราะอาจทำให้ปลั๊กอินการตรวจสอบสะดุด อะไรทำให้คุณไม่สามารถเรียกฟิลด์เหล่านั้น location, groupsize และ eventdate

อัปเดต

ตามตรรกะของการประกาศฟิลด์ คุณไม่มีวงเล็บปีกกาสำหรับฟิลด์หลัง:

        company: {
            required: true,
            minlength: 2
        },
        '00NG0000008iHK7': { //Program Location = missing opening curly
            required: true,
            minlength: 2
        },
        '00NG0000008iHKH': { //Group Size - opening curly
            "groupMin"}, // closing curly
        '00NG0000008iHKR': { //Event Date - opening curly
            required: true,
            minlength: 3
        },
        '00NG0000008iHKg': {
            "seoNO", // opening curly
        }
person crowjonah    schedule 27.11.2012
comment
@CaitlinHavener คุณอาจไม่สามารถเปลี่ยนชื่อ id ได้ แต่คุณไม่สามารถคาดหวังให้รหัสที่ไม่ถูกต้องทำงานได้อย่างถูกต้อง - person Sparky; 27.11.2012