开发者

problem with jquery validation

开发者 https://www.devze.com 2023-02-03 11:56 出处:网络
I have a simple form with 6 textfields. I use Ajax to save information. When I click edit button, jQuery validator identified the error but allow to submit.

I have a simple form with 6 textfields. I use Ajax to save information. When I click edit button, jQuery validator identified the error but allow to submit. Actually it work just for last input!

I used class="number fillone" to check them to enter just number and also enter at least one of 6...

$('#edit_midterm').click(function() {

    $("#edit_midterm_form").validate({
        rules:{
            queiz: {number:true, max:6,
            seminar:{number:true, max:6,
            tamrin:{number:true, max:6,
            midterm:{number:true, max:6},
            tahghigh:{number:true, max:6},
            project:{number:true, max:6}
        },
        require_from_group: [1,".fillone"],
        submitHandler: function() 
        {
            $("#loading_edit").ajaxStart(function(){$(this).show();});
            $("#loading_edit").ajaxStop(function(){$(this).hide();});

            $.ajax({
                type:"POST",
                url:"course/term/ajax_mlist.php",  
                data:($("#edit_midterm_form").serialize()),
                success:function(data){
                if((data.result)=='true')
                    $("#result_edit").html(data.message);
            }, 
            dataType:"json"});
            return false;
        }


    });
});

and this is my form:

<form name="edit_mid" action="" id="edit_midterm_form" method="post">
        <input type="hidden" name="type" value="edit">
        <input type="hidden" name="operation" value="yes">
        <input type="hidden" name="ic" value="'.$id.'">
        <table class="list" width="100%" border="0" align="center" cellspacing="1" cellpadding="5" dir="rtl">
        <tr>
            <th colspan="2">Edit Form</th>
        </tr>
        <tr>
            <td width="100">Quize</td>
            <td><span class="red_error"><input type="text" name="queiz" id="queiz" max="6" class="number fil开发者_开发问答lone" value="'.$object->queiz_1.'"></span></td>
        </tr>
        <tr>
            <td>Lecture</td>
            <td><span class="red_error"><input type="text" name="seminar" id="seminar" max="6" class="number fillone"  value="'.$object->seminar_3.'"></span></td>
        </tr>
        <tr>
            <td>home Work</td>
            <td><span class="red_error"><input type="text" name="tamrin" id="tamrin" max="6" class="number fillone"  value="'.$object->tamrin_5.'"></span></td>
        </tr>
        <tr>
            <td>Midterm</td>
            <td><span class="red_error"><input type="text" name="midterm" id="midterm" max="6" class="number fillone"  value="'.$object->midterm_2.'"></span></td>
        </tr>
        <tr>
            <td>Search</td>
            <td><span class="red_error"><input type="text" name="tahghigh" id="tahghigh" max="6" class="number fillone"  value="'.$object->tahghigh_4.'"></span></td>
        </tr>
        <tr>
            <td>project</td>
            <td><span class="red_error"><input type="text" name="project" id="project" max="6" class="number fillone"  value="'.$object->project_6.'"></span></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" id="edit_midterm" value="Edit" class="buttom_edit">
            <img src="../template/icon/ajax_loader_1.gif" id="loading_edit">
            <span id="result_edit"></span>
            </td>
        </tr>
      </table></form>


Not sure what error you are getting, but I can see at a glance there are some closing curley braces missing:

rules:{
                        queiz: {number:true, max:6},
                        seminar:{number:true, max:6},
                        tamrin:{number:true, max:6},
                        midterm:{number:true, max:6},
                        tahghigh:{number:true, max:6},
                        project:{number:true, max:6}
                        },


actually here is rong , in my code it is correct. the problem is that when i use this code for controll at least enter one of 6 the other don't work .

in my form it works just for last one!

this is code:

jQuery.validator.addMethod("require_from_group", function(value, element, options) {
    numberRequired = options[0];
    selector = options[1];
    var validOrNot = $(selector, element.form).filter(function() {
         return $(this).val();
      }).length >= numberRequired;

    if(!$(element).data('being_validated')) {
    var fields = $(selector, element.form);
    fields.data('being_validated', true).valid();
    fields.data('being_validated', false);
    }
    return validOrNot;

}, jQuery.format("please enter {0} Of this"));
0

精彩评论

暂无评论...
验证码 换一张
取 消