0

I have several jQueryUI dialogs with Ok and Cancel and radio buttons (no text input).

My requirements are:

OK button should be right of the Cancel button and Ok button should be in focus:

  1. when the dialog opens,
  2. after any user click or drag.

Requirement no 1 can be implemented by giving the Ok button an id and the following code:
open: function(event, ui) { $('#OkButton').focus(); },

Requirement no 2 is harder. It could be implemented by defining focusing delegates for a lot of events:

  • .ui-dialog-titlebar click
  • .ui-dialog-buttonpane click
  • dragStop
  • etc

But surely there must be a simpler way?

1 Answer 1

0

Try this code. myDialog is main dialog div When you drag your dialog this will do the job

jQuery('.myDialog').bind('move', function(e) {
    $('#OkButton').focus();
}).bind('moveend', function() {});

and when you click on your dialog main div this will do the job.

jQuery('.myDialog').click(function(){
    $('#OkButton').focus();
});
2
  • Thank you for your answer. Your first suggestion is maybe better implemented by defining a dragStop event handler on the Diaolog Widget. Your second suggestion does not work, but this one does jQuery('.ui-dialog').click(function(){ $('#okButton').focus(); return true; } Commented Jan 20, 2013 at 7:38
  • Thanks for reviewing. and by "mydialog" class i actually meant the main div class which in case of jQuery dialog box is jQuery native ".ui-dialog"
    – Rizstien
    Commented Jan 20, 2013 at 7:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.