簡體   English   中英

在子模態對話框上按Enter會在父模態對話框(即11和邊)上觸發Enter

[英]Pressing enter on child modal dialog fires enter on parent modal dialog (ie11 and edge)

我有兩個引導模式對話框窗口,一個創建另一個。 在孩子的文本輸入上按下Enter鍵時,它也會在父對象上觸發一個事件。 要關注父級的最后一個按鈕是創建子級的按鈕,這將導致立即重新創建子級。

我發現了一些類似的問題,這些問題的狀態是確保對話框上的“確定”按鈕的類型為= button,因為它們默認為提交。 我確保按鈕具有按鈕類型,但是問題仍然存在,盡管在chrome中效果很好。

這里有一個例子說明了unk車手正在發生的事情 這是第一個模式窗口。

<script type="text/ng-template" id="myModalContent.html">
        <div class="modal-body">

        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" type="button" ng-click="shownewwindow()">New Modal</button>
            <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
        </div>
    </script>

這是第二個。

<script type="text/ng-template" id="modal2.html">
        <div class="modal-body">
           <input type=textarea value="test" ng-keypress="keydown($event)" autofocus></input>
        </div>
        <div class="modal-footer">
            <button class="btn btn-default" type="button" ng-click="ok()">ok</button>
            <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
        </div>
    </script>

這是確定,取消和擊鍵的功能。

$scope.ok = function () {
    console.log("ok");
    $uibModalInstance.dismiss({completed: true});
  };

  $scope.cancel = function () {
    $uibModalInstance.dismiss('cancel');
  };

  $scope.keydown = function(event) {
            var enterKeyCode = 13;
            $uibModalInstance.dismiss({completed: true});
  }

謝謝任何關於如何防止在按下Enter鍵時反復創建孩子的想法。

嘗試在單擊按鈕時禁用它。

<button ng-disabled="aScopeVar" ng-click="setAScopeVarToTrue()">My button</button>

創建子項后,請不要忘記將aScopeVar設置為true。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM