删除tr后,提交按钮将被禁用

时间:2016-12-20 09:00:21

标签: php jquery formvalidation-plugin bootstrapvalidator

从表格中删除tr后,我的提交按钮被禁用。我正在使用bootststrap验证,我在firebug中收到此错误:

enter image description here

它给了我

  

类型错误n未定义。

当我从操作中单击删除按钮时,tr已成功删除,但当我填写其余字段并单击提交按钮时,提交按钮将被禁用。

enter image description here

这是我的HTML:

<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
    <div class="row">
        <div class="table-class" id="specialTemplate">
            <table class="table table-bordered">
                <thead>
                    <tr style="text-align: center;">
                        <td style="width:15%">Services</td>
                        <td style="width:15%">Duration</td>
                        <td style="width:15%">Last Price </td>
                        <td style="width:15%">Discount Price </td>
                        <td style="width:15%">Actual Price</td>
                        <td style="width:15%">Action </td>
                    </tr>
                </thead>
                <tbody class="appendSpecial">
                    <?php $duration = array("10mins","20mins","30mins","45mins","1hr","1hr-15mins","1hr-30mins","1hr-45mins","2hrs","3hrs"); ?>
                                                @foreach($specialoffers as $key=> $alloffers)
                    <tr id="s-tr-{{ $alloffers['id'] }}">
                        <input type=hidden name="id[]" value="{{ $alloffers['id'] }}">
                        <td id="s-td-{{$alloffers['id'] }}" >{{ $alloffers['s_name'] }}</td>
                        <td>
                           <div class="time-class">
                               <div class="form-group">
                                   <select class="select-class" name="s_duration[]">
                                       <option value="">Select</option>
                                                                @foreach($duration as $value)

                                       <option>{{$value }}</option>
                                                                @endforeach
                                   </select>
                              </div>
                         </div>
                     </td>
                     <td>
                         <div class="form-group">
                             <input class="form-control" type="text" name="s_lastprice[]" placeholder="Price" >
                        </div>
                     </td>
                     <td>
                         <div class="form-group">
                             <input class="form-control" type="text" name="s_discount[]" placeholder="Discount Price" >
                         </div>
                     </td>
                     <td>
                         <div class="form-group">
                             <input class="form-control" type="text"  name="s_actual[]" placeholder="Actual Price">
                         </div>
                     </td>
                     <td>
                         <div class="btn-del-edit">
                             <button  type="button" rel="{{$alloffers['id'] }}"  class="btn btn-info btn-edit getSpecial" data-toggle="modal" data-target="#myModal-specialedit"><i class="fa fa-pencil" aria-hidden="true"></i></button>
                             <button type="button" id="delete-{{ $alloffers['id'] }}" class="btn btn-danger btn-del deleteSpecial"><i class="fa fa-times" aria-hidden="true"></i></button>
                        </div>
                    </td>
               </tr>
       @endforeach
           </tbody>
       </table>
    </div>
  </div>
</div>

我的jQuery和AJAX:

$(document).on('click','.deleteSpecial', function(){
    var tdid = $(this).attr('id');
    var special = tdid.split('-');
    var id = special[1];
    $.ajax({
        type:"POST",
        url: "delete-special-offer",
        data: { id :id },
        success:function(resp){
            if($.trim(resp) == "success"){
                alert("Deleted Successfully!"); 
                var $template = $('#specialTemplate'),
                $clone    = $template
                $('#sellerProfile')
                .formValidation('addField', $clone.find('[name="s_lastprice[]"]'))
                .formValidation('addField', $clone.find('[name="s_discount[]"]'))
                .formValidation('addField', $clone.find('[name="s_actual[]"]'))
                .formValidation('addField', $clone.find('[name="s_duration[]"]'))
                $("#s-tr-"+id).remove();
            }
            else{
                alert("failed"); return false;
            }
        }
    });
});

1 个答案:

答案 0 :(得分:0)

用户界面中的

提交按钮不起作用。要删除您只需使用$("#s-tr-"+id).remove();.,那么您想要执行以下操作: -

        var $template = $('#specialTemplate'),
        $clone    = $template
        $('#sellerProfile')
        .formValidation('addField', $clone.find('[name="s_lastprice[]"]'))
        .formValidation('addField', $clone.find('[name="s_discount[]"]'))
        .formValidation('addField', $clone.find('[name="s_actual[]"]'))
        .formValidation('addField', $clone.find('[name="s_duration[]"]'))

因为根据控制台日志,它显示错误是表单验证失败