jQuery validation plugin multiple forms

后端 未结 1 842
有刺的猬
有刺的猬 2021-01-21 19:49

I\'m trying to add some functionality to a series of forms to validate two checkboxes. I\'m using the jQuery validation plugin and for the life of me can\'t get it working. In f

相关标签:
1条回答
  • 2021-01-21 20:36

    As stated in the comments, you should add a ',' before rules:, and manipulate a jquery form object in your submitHandler, like this :

    $(".offer").each(function () {
        $(this).validate({
            submitHandler: function (form) {
                var x = $(form).find('input[name=description]').val();
                var y = $(form).find('input[name=original_description]').val();
                var z = similar_text(x, y, 1);
                alert("Description: " + x + " original_description: " + y + " z: " + z)
                if (z > 50 && !isNaN(z)) {
                    alert("Description too similar to original. Please make it less similar");
                    return false;
                }
                form.submit();
            },
            rules: {
                added_by: {
                    required: true
                }
            },
            messages: {
                added_by: {
                    required: 'Please select your name'
                }
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题