How to cancel opening the jQuery UI dialog box?

I have the following:

container.dialog().bind('dialogopen', function(event, ui)
  {
     ...
     if (someCondition)
     {
         $(this).dialog('close'); // the dialog is not closed!
     }
  }

How should i work?

Unfortunately, there is no 'beforeopen' event to connect.

+3
source share
3 answers

The problem here is that you need to bind the event to . You are currently invoking .dialog()that opens a dialog box (if autoOpen: falsenot an option provided). This means that before it is executed .bind(....), this event has already occurred. The solution is to simply bind before the event occurs, for example:

container.bind('dialogopen', function(event, ui) {
  if (someCondition) {
     $(this).dialog('close'); // the dialog is not closed!
  }
}).dialog(); //.dialog() fires "dialogopen" as part of it execution

, , , , , .

, dialogopen , ( )... , , DOM, .

+4

autoOpen ( false), , someCondition. .dialog("open")...

+1

"beforeopen".

0

Source: https://habr.com/ru/post/1752137/


All Articles