Search code examples
javascriptdialogdojo

Dojo declarative ConfirmDialog hiding cancel button


This question shows how to hide a cancel button on a programmatic ConfirmDialog in Dojo.

How to do the same thing, i.e. hiding the Cancel button, if the ConfirmDialog is declarative as below in a HTML template:

<div class="confirmDialog" 
     data-dojo-type="dijit/ConfirmDialog" 
     data-dojo-attach-point="confirmDialogAttachPoint" 
     data-dojo-props="title:'MyDialog', content:'Some Content', closable:false" 
     data-dojo-attach-event="onExecute:doSomething">
</div>

Doing the following in postCreate function of the corresponding widget works:

domStyle.set(this.confirmDialogAttachPoint.cancelButton.domNode, "display", "none");

However, I want to know/learn if this could be done declaratively in the HTML file itself.


Solution

  • just adding a css to your widget css will hide your button :

    .dijitDialogPaneActionBar .dijitButton:nth-child(2) {
      display: none;
    }
    

    See below snippet :

    require(["dijit/ConfirmDialog", "dijit/form/TextBox", "dijit/form/Button"]);
        .dijitDialogPaneActionBar .dijitButton:nth-child(2) {
          display: none;
        }
    <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/ConfirmDialog" data-dojo-id="myDialog" title="dialog">
        Hi !
      </div>
    
      <button data-dojo-type="dijit/form/Button" type="button" onClick="myDialog.show();">
        Show me!
    </button>
    </body>