gpt4 book ai didi

javascript - 如何停止/暂停/覆盖Dojo的confirmDialog隐藏执行?

转载 作者:太空宇宙 更新时间:2023-11-04 16:03:42 25 4
gpt4 key购买 nike

我有 Dojo confirmaDialog,我需要在提交表单之前实现一个简单的验证,并防止模式在出现验证错误时关闭。

这就是我现在拥有的:

var followUpDialog = new ConfirmDialog({
title: "Create new follow-up",
content: handleMessageContent(),
style: "width: 730px",
onShow: function() {
modalContainer = this.containerNode;
fillInputFields(modalContainer);
},
onExecute: function () {
if(!this.get("state")) {
handleSubmit();
} else {
// Need something like event.preventDefault here.
}

},
onCancel: function () {
//Do nothing...
}
});

基本上,当按下提交按钮时,我需要在某些条件下不执行任何操作。

最佳答案

当您单击“确定”时Button , onExecute称为 ,最后调用 hide对话框功能。

您可以将自定义代码添加到 Okbutton Click 事件,或者只需覆盖 ConfirmDialog.js并创建您的自定义事件;举例说明

首先覆盖ConfirmDialog:

CustomConfirmDialog = declare([ConfirmDialog],{
postCreate:function(){
this.inherited(arguments);
//check if realy passed parm is a function
if(typeof(this.submitFunction) == "function") {
this.okButton.on("click",lang.hitch(this,function(evt){
if(!this.submitFunction()) evt.preventDefault();

}));
}
}
});

创建您的提交函数:

submit = function(){
//submit code
}

然后,当实例化最后一次时,在选项参数中发送提交函数(此处它作为 submitFunction 名称属性发送):

var followUpDialog = new CustomConfirmDialog({
id:'myDialog',
...
// function of submit
submitFunction:submit,....
....
}

下面是一个工作示例:

require(["dijit/ConfirmDialog", "dojo/_base/declare","dojo/on", "dijit/form/Button","dijit/registry","dojo/_base/lang","dojo/ready"],
function(ConfirmDialog,declare,On,Button,registry,lang,ready){
i=0;

// sample function to submit your form
submit = function(){
//Swap between true and false.
i ? ++i : --i;
return i;
}

// overide ConfirmDialog
CustomConfirmDialog = declare([ConfirmDialog],{
postCreate:function(){
this.inherited(arguments);
//check if realy passed parm is a function
if(typeof(this.submitFunction) == "function") {
this.okButton.on("click",lang.hitch(this,function(evt){
if(!this.submitFunction()) evt.preventDefault();

}));
}
}
});


ready(function(){

registry.byId("btn").on("click",function(e){
followUpDialog.show();
});
// instantiate new custom dialog
var followUpDialog = new CustomConfirmDialog({
id:'myDialog',
title: "Create new follow-up",
content: "content !",
style: "width: 730px",
//send submit function here
submitFunction:submit,
onShow: function() {
//modalContainer = this.containerNode;
//fillInputFields(modalContainer);
},
onExecute: function (e) {
console.log("execute called");
},
onCancel: function () {
//Do nothing...
}
});

})
}
);
<script type="text/javascript">
dojoConfig = {isDebug: true, async: true, parseOnLoad: true}
</script>

<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" rel="stylesheet"/>
<body class="claro">
<div data-dojo-type="dijit/form/Button" id="btn"> click me </div>
</body>

这里还有一个Fiddle

关于javascript - 如何停止/暂停/覆盖Dojo的confirmDialog隐藏执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42067470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com