简体   繁体   English

dojo 1.4阻止yes / no对话框替换window.confirm

[英]dojo 1.4 blocking yes/no dialog replacement for window.confirm

I am stuck in dojo 1.4. 我陷入了dojo 1.4中。
Need a synchronous (blocking) dialog replacement for window.confirm(). 需要window.confirm()的同步(阻止)对话框替换。
why : I would like the buttons to be YES/NO instead of OK/CANCEL. 为什么:我希望按钮为“是/否”而不是“确定/取消”。
This dialog will be called from multiple parts of the app -- so needs proper cleanup. 该对话框将从应用的多个部分调用-因此需要适当的清理。 Is there a dojo library that has this functionality ? 是否有具有此功能的dojo库?
I would prefer all dynamic code so I can include this new dialog from within a .js file or a html/jsp file but something working is appreciated. 我希望使用所有动态代码,因此我可以从.js文件或html / jsp文件中包含此新对话框,但是可以正常工作。

You cannot make it synchronous, but you can prevent the form from submitting by event.preventDefault() or onsubmit="return false;" 您不能使其同步,但是可以通过event.preventDefault()onsubmit="return false;"阻止表单提交onsubmit="return false;" as @FakeRainBrigand mentioned. 就像@FakeRainBrigand提到的那样。

Here is a working example: http://jsfiddle.net/phusick/73PuE/ . 这是一个工作示例: http : //jsfiddle.net/phusick/73PuE/

在此处输入图片说明

It employs the confirm dialog I mentioned in the comment above. 它使用我在上面的评论中提到的确认对话框 It is written in Dojo 1.8, but it should be more or less the same as in 1.4, just use dojo.connet instead of dojo/on : 它是用Dojo 1.8编写的,但应该与1.4大致相同,只需使用dojo.connet而不是dojo/on

var form1 = dom.byId("form1");

on(form1, "submit", function(event) {
    event.preventDefault();
    var form = event.target;
    MessageBox.confirm({ message: "Submit form?" }).then(function() {
        // submit the form upon a click on `Yes`
        form.submit();
    });        
});

You can achieve the same in plain vanilla JavaScript : 您可以使用普通的JavaScript实现相同的功能:

function confirmHandler(event) {
    event.preventDefault();

    var form = event.target;
    // ask for a confirmation and if confirmed invoke:
    // form.submit();
}

Register handler on the form: 在表格上注册处理程序:

<form onsubmit="confirmHandler(event);">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM