Boostrap Modal中的表单不会重置

时间:2017-09-27 13:51:39

标签: javascript meteor bootstrap-modal adminlte

我使用下面的点击事件重置表单。

'click .resetBulkAssignForm' : function(events, template){
    console.log('Reset', $(".bulkAssignForm")[0]);
    $(".bulkAssignForm")[0].reset();
    $(".bulkAssignForm").find("select").val("");
    $('#firmName').select2('data', null);
},

我也尝试了SO上提供的大部分答案来解决这个问题。

问题:如何在Bootstrap Modal中重置表单?

下面是带控制台输出的模态图像。

enter image description here

  

注意:我使用的是AdminLTE 2.3.11,Select2。另请注意我已在SO how-to-clear-all-input-fields-in-bootstrap-modal-when-clicking-data-dismiss-butthow-to-reset-form-body-in-bootstrap-modal-box

等SO链接中尝试过解决方案

如果您需要查看,请添加HTML代码。

<div id="myBulkModal" class="modal fade modal-primary" role="dialog">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h2 class="modal-title">Bulk Assignment</h2>
        </div>
        <div class="modal-body">
           <section class="content">
             <form class="bulkAssignForm">
               <fieldset>
                 <div class="row">
                    <input type="hidden" id="taskIdInput" value="{{getTaskId}}" />
                 </div>
                 <div class="row">
                   <div class="input-group col-sm-12">
                     <label for="firmName">Firms</label><br />
                     <select id="firmName" multiple class="form-control input-lg" required>
                       {{#each firmNamesFromAssignment}}
                          <option value="{{value}}">{{label}}</option>
                       {{/each}}
                     </select>
                   </div>
                 </div>
                 <br />
                 <div class="row">
                   <div class="input-group col-sm-12">
                     <label for="assignee">Assignee</label><br />
                     <select id="assignee" class="form-control input-lg" required>
                       <option  selected="selected" value="">Select Option</option>
                       {{#each usersSelect2}}
                          <option value="{{value}}">{{label}}</option>
                       {{/each}}
                     </select>
                   </div>
                 </div>
                 <br />
                 <div class="row">
                   <div class="input-group col-sm-12">
                     <label for="reviewedBy">Reviewer</label><br />
                     <select id="reviewedBy" class="form-control input-lg" required>
                       <option  selected="selected" value="">Select Option</option>
                       {{#each usersSelect2}}
                          <option value="{{value}}">{{label}}</option>
                       {{/each}}
                     </select>
                   </div>
                 </div>
                 <br />
                 <div class="row">
                   <!-- buttons -->
                   <button type="submit" class="btn btn-outline">
                     <span class="glyphicon glyphicon-ok"></span> Assign
                   </button>
                   &nbsp;&nbsp;
                   <button type="button" class="btn btn-outline resetBulkAssignForm">
                     <span class="glyphicon glyphicon-off"></span> Reset
                   </button>
                   &nbsp;&nbsp;
                   <button type="button" class="btn btn-outline" data-dismiss="modal">
                     <span class="glyphicon glyphicon-refresh"></span> Close
                   </button>

                 </div>
               </fieldset>
             </form>
           </section>
        </div>
      </div>
    </div>
  </div>

1 个答案:

答案 0 :(得分:0)

更改Select2基础<select><input>的值后,您必须触发change事件,以便此更改将由Select2代码处理适当渲染:

$(".bulkAssignForm").find("select").val("").trigger("change");

AutoForm Demo test page 上成功测试。