Do not focus on button
Closed this issue · 5 comments
I'd like to be able to focus on my first form element, but the modalbox is stealing the focus and putting it on the button instead.
Hmm, it actually worked as you described.
Seems to be a bug :-).
I changed line 109 to
var focusable = dialog.find("a, input:not([type=hidden]), .btn, select, textarea, button")
and now it works as intended :)
The system still falsely puts its focus on normal hyperlinks, rather than just the buttons.
That is actually intended. The reason is that you can tab through the content to the first button (try it!).
The behaviour on dialog focus is consistent with the behavior of a page load (will focus the first element on the page, too).
You can patch the lib yourself if you want to (will check if i can provide you a patch for that).
I am still not 100% sure what your desired behavior is. Whatever you would like to achieve, you can always register a event listener on the dialog which will perform a custom initialization on content load.
var dialog = $(".my-dialog").dialog2();
dialog.bind("dialog2.content-update", function(event) {
var focusable = $(this).parent().find(".modal-footer").find("input[type=submit], input[type=button], .btn, button");
if (focusable.length) {
focusable = focusable.eq(0);
}
focusable.focus();
});
This works for the 1.2-wip
branch of the dialog2 plugin. For older versions of it, use the event dialog2.ajax-complete
trigger. Hope this helps!