How to prevent a WebDialog to be closed using the “esc” key?


As can be demonstrated in a test project, a web dialog can be closed by the user by just pressing the “esc” key. Under certain circumstances, this is not wanted.

But how can we prevent this behaviour? We can’t trap the “esc” key and Xojo doesn’t provide a way to turn that “feature” off.

using javascript it could work

myModal.dataset.keyboard = 'false';

or for bootstrap 5 = 'false';

Do you want to add a Feature Request to add ‘Static Backdrop’ for Bootstrap Modals?

Thanks, but it doesn’t work (it’s just ignored). I tried:
me.ExecuteJavaScript(“ = ‘false’;”)
in the Opening event (and the other variation you suggest, as I’m not sure on which strap I run).

I don’t know. I’m not really a “web guy”, and when I read it’s a “modal plugin”, my reaction is I’d like Xojo to avoid relying on external resources as much as possible.

I’m sorry, I mean: create an Issue so Xojo add the option that Bootstrap 5 offers (Static Backdrop), so we don’t need to add JavaScript or other workarounds.

1 Like

it’s not “mymodal” but the control id of your dialog, and a ‘#’ before in the javascript, and “_modal” for the dialog…)
something like (for xojo 2023r2+)

Me.ExecuteJavaScript( "$('#" + Me.ControlID + "_modal') = 'false';" )

and if you want to prevent clicking outside the dialog to dismiss it you can use :

Me.ExecuteJavaScript( "$('#" + Me.ControlID + "_modal') = 'static';" )

ps: not tested, I use this in my websdk’s

Capture d’écran 2023-11-09 à 18.50.06

Ah, sorry.
If I find time to create an Issue in the upcoming days, I’ll gladly do it.

Thanks. I tried your new example (with and without “.bs”) and they’re still ignored.
Are Javascript errors logged somewhere so I could see what’s the problem?

Thanks; that’s already handled by Xojo, though.

So it should have worked in my test as well :thinking:.

yes use the developper menu in most browsers, and display the console

Not necessarily as Jean-Yves uses a WebSDK and not the XojoDialog that could be implemented differently.

in which event did you write the executejavascript code ?

I tried in the dialog’s opening and showing events (one at a time, of course).

well it seems my websdk’s for the modaldialog are not working under bootstrap v5 !
the dialog is not even shown …

so, it’s working again, and I use setAttribute(“data-bs-keyboard”,“false”) under bootstrap 5
but it seems xojo dialog are modified “on the fly” and you can’t add a javascript to the modal dialog control…
it works with a websdk, but I don’t see how to make it work with xojo built-in modals

1 Like

may be @Ricardo_Cruz can tell us more about this issue ?

Thanks for your attempts.
Granted, additional information would be welcome.