1

テキストボックスを複製するシナリオがあります。次に、ボックス入力ごとに、入力が正しいか間違っているかを(ajax呼び出しを介して)dbに対して検証します。入力が無効な場合はエラーボックスを表示し、最後にjqueryバリデーターメソッドを使用して、ボックスにエラーメッセージがあるかどうかをチェックし、エラーを発生させてフォームを投稿しません。しかし、問題は、値が正しいか間違っているかに関係なく、すべてのテキストボックスのvalidtor show error msgです。

         <table id="next_module" class="table">
                <thead>
                        <th>Message Id</th>

                </thead>
                <tbody>


        <tr id="row_0">
                    <td>
                        <input id="messge-id_0" class="valid_next_messge_module numeric messgeing_id required" name="messge-id_0" type="text" onblur="get_messge_detail($(this));" value="">
                        <label id="txterr_0" class="next_messge_error" style="display: none;color:red;width:0px">*</label></td>
        </tr>
        </tbody>
        </table>


            <script>
            var $underscore = $("#next_module tbody tr:first");
            var $clone = $underscore.clone();
            $clone.attr('id', $clone.attr("id") + i );
            $clone
            .find("input,label")
            .each(function() {
                $(this).attr({
                    id: this.id + i,
                    name: this.name + i,
                    value:'',
                    src:''
                });
            });
            $clone
            .appendTo("#next_module")
            .show();
            i++;
            </script>



            <script>
            function get_messge_detail(obj)
            {
                var messge_id = $.trim(obj.val());
                var id_num = (obj.attr('id')).split('_')[1];
                if(messge_id)
                {
                var url = "/server/messge/ajax_get_messge_detail/";
                var data = {'messge_id':messge_id};

                $.ajaxSetup({async:false});

                $.post(url, data, function (response) {


                    if (response["msg"])
                    {
                        no error found 
                    }
                    else
                    {
                        $("#"+(obj.attr('id'))).focus();
                        $("#txterr_"+ id_num).show();
                    }
                });
            }

            jQuery.validator.addMethod("valid_next_messge_module", function() {
                var status  =  false;
                if (parseInt( $('.next_messge_error:visible').length) > 0)
                    return false;
                else
                    return true;
            }, "Please enter valid next messgeing module id.");

            </script>
4

0 に答える 0