I want to disable X Button on top right in this dialog , How can i do it

dialogWindows.detail(this, ExternalAccount.class)
.withViewId(“UserInformationAdminORG.detail”)
.editEntity(externalAccount)
.open()
.addAfterCloseListener(closeEvent → {
redirect(event, isInGroup);
sessionDataUtils.setAttribute(“homeView”, true);
});

I want to disable X Button on top right in this dialog , How can i do it

Hi!

There are several ways to remove a close button from a dialog.

  1. If you are using the latest version of the Jmix framework, you can do this simply and concisely.
    Put the following code snippet into your ExternalAccount view controller:

     @Override
     protected void configureDialogWindowHeader(DialogWindowHeader header) {
         header.getElement().getParent().getComponent()
                 .map(Div.class::cast)
                 .ifPresent(headerRoot -> {
                     // close button is placed at the last index
                     Component closeButton = headerRoot.getComponentAt(headerRoot.getComponentCount() - 1);
                     closeButton.removeFromParent();
                 });
     }
    
  2. If you are using a version < 2.6, you can use the following code to open your dialog:

         DialogWindow<View<?>> build = dialogWindows.detail(this, User.class)
                 .newEntity()
                 .build();
    
         View<?> view = build.getView();
    
         Dialog dialog = UiComponentUtils.findDialog(view);
         // root of the header
         Element root = dialog.getHeader().getElement().getChild(0);
         Element closeButton = root.getChild(1);
    
         closeButton.removeFromParent();
         build.open();
    
  3. Add CSS class to ExternalAccount view XML and remove button using styles. This is not the best way because users will be able to restore close button using browser dev tools

Best regards,
Dmitriy

1 Like