Dojo ConfirmDialog隐藏取消按钮

时间:2019-01-20 07:56:25

标签: javascript dialog dojo dijit.dialog

我有一个道场ConfirmDialog,如下所示:

this.myDialog = new ConfirmDialog({
                   title: "My Dialog",
                   content: "Do you want to continue?",
                   class: "confirmDialog",
                   closable: false
                });

// change button labels
this.myDialog.set("buttonOk","Yes");
this.myDialog.set("buttonCancel","No");

// register events
this.myDialog.on("execute", function() { 
                              self.continueSomething() 
                            });

稍后基于某些条件,我将动态更新ConfirmDialog,如下所示:

this.myDialog.set("title", "New Title");
this.myDialog.set("content", "Its too late. Press ok to re-route.");
this.myDialog.set("buttonOk","Ok");

在此阶段,Cancel按钮没有任何功能。我怎么藏起来?

以下任何一项工作:

this.myDialog.cancelButton.hide();
//or
this.myDialog.cancelButton.set("display", "none");
//or 
this.myDialog.cancelButton.set("display", none);

我可以将其禁用为:

this.myDialog.cancelButton.set("disabled", true);

但这看起来并不正确。我想完全隐藏Cancel按钮。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

cancelButtonbutton Dijit,如果您要隐藏/最后显示此内容, 您必须通过快速键入this.myDialog.cancelButton.domNode来访问它的domNode 并使用dojo/dom-style隐藏/显示如下

let cancelBtnDom = this.myDialog.cancelButton.domNode;
domStyle.set(cancelBtnDom, 'display', 'none');

请参阅下面的工作摘要(禁用使用外部按钮启用)

require(["dijit/ConfirmDialog", "dojo/dom-style", "dojo/domReady!"], function(ConfirmDialog, domStyle){
    myDialog = new ConfirmDialog({
        title: "My ConfirmDialog",
        content: "Test content.",
        style: "width: 300px"
    },"dialog");
    
    let cancelBtn = myDialog.cancelButton.domNode;
    
    let switchBtn = document.getElementById("switch");
    
    switchBtn.addEventListener("click",function(){
     let display = domStyle.get(cancelBtn, "display") !== "none" ?  "none" : "";
     console.log(display);
      domStyle.set(myDialog.cancelButton.domNode, 'display', display);
    });
    
});
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" rel="stylesheet" />

<body class="claro">
  <div class="dialog"></div>
  <button onclick="myDialog.show();">show</button>
  <button id="switch" >enable/Disable cancel button</button>
</body>