JS:如何覆盖 AlertifyJS 中的 keyupHandler(event) 函数



问题是我在 Alertify 对话框中使用 Select2 组合框,现在每当我尝试通过按 Enter 键使用键盘选择 select2 选项时,对话框就会关闭,因为 Enter 键绑定到 Ok 按钮和 ESC 键绑定到取消按钮,我想在不更改源 js 的情况下覆盖 keyupHandler 处理程序函数。

来源: https://github.com/MohammadYounes/AlertifyJS/blob/master/build/alertify.js +1269

警报.js代码:

import alertify from 'alertify';
// How can I override the default keyupHandler function after importing it in my code?

我想添加验证,如果 event.target 是 Select2 并且它是打开的,那么不要触发关闭对话框的事件。

您可以组合来自两个库的事件来实现此目的,首先侦听 select2 的打开和关闭事件,然后使用它们来允许或拒绝关闭对话框。

var isClosed = false
// wire select2 events
$('select').select2().on('select2:open', function(e){
  isClosed = false
}).on('select2:close', function(e){
  setTimeout(function(){
    isClosed = true
   },200)
});
// wire alertifyjs events
alertify.confirm().set('onok', function(){
  return isClosed
})

最新更新