Disable v4.x IdentityManager login prompt

778
2
Jump to solution
02-11-2022 10:48 AM
NilsBabel1
Occasional Contributor

I have an application using 4.22 of the JavaScript API. It references several layers from different sources.  When one of these layers from an outside ArcGIS Online Organization changes or is unavailable, for whatever reason, the API presents the user with the ArcGIS Online sign in dialog.  It must assume the layer it is looking for is secured and maybe it can reach it by signing in.  This makes no sense to my users and I would like to disable the dialog or cancel the dialog when it opens.  That way the layer will fail and notify the user it is not available.  However, I can't find a way in the Identity Manager to do this.  The closest I can find is the Identity Manager has a dialog-create event.  I can create a handler that catches the on dialog create event.  But the only thing I can do at that point is set the visibility of the dialog to false.  That doesn't actually cancel it.  The layer is still waiting for input from the user and never fails.  Is there another way to disable, cancel, or suppress the dialog?  

0 Kudos
1 Solution

Accepted Solutions
NilsBabel1
Occasional Contributor

I found out you can drill down through the container to get to the cancel button and then call the click method.  You have to set a handler on the dialog-create event and then when the dialog is ready get a reference to the button and call the click event.  

 

esriId.on('dialog-create', () => {
      esriId.dialog.when(() => {
        const dialogHtml: any = esriId.dialog.container;
        const cancelBtn: HTMLInputElement = dialogHtml.childNodes[0].childNodes[2].childNodes[0].childNodes[3].childNodes[1];
        cancelBtn.click();
      });
    });

View solution in original post

2 Replies
NilsBabel1
Occasional Contributor

I found out you can drill down through the container to get to the cancel button and then call the click method.  You have to set a handler on the dialog-create event and then when the dialog is ready get a reference to the button and call the click event.  

 

esriId.on('dialog-create', () => {
      esriId.dialog.when(() => {
        const dialogHtml: any = esriId.dialog.container;
        const cancelBtn: HTMLInputElement = dialogHtml.childNodes[0].childNodes[2].childNodes[0].childNodes[3].childNodes[1];
        cancelBtn.click();
      });
    });
JasonDoingMaps
New Contributor III

Another option would be to call the _close function on the dialog object. It's technically a private function (per the underscore), so potentially subject to change without notice. But then again, the layout of the HTML that you're relying on to find the right child node for the cancel button is just as susceptible to change. This at least reads better.

IdentityManager.dialog._close();
0 Kudos