0

I'm using jQuery UI 1.8.4, I have a context menu that opens up a dialog window. When the dialog window opens it doesn't get focused on. I try setting the autofocus in my checkbox element, also tried using $('input[type="checkbox"]').eq(0).focus() and $('input[type="checkbox"]').first().focus(). I also tried using open (event, ui) and focus (event, ui). None of the elements in the dialog gets focused on.

If I tab using the keyboard it doesn't get into the dialog window until its done with the tabbable objects behind it. The only way I got for the focus to work is if I used the mouse and clicked on the dialog. What would be causing my focus to not work? Here is my code.

assignmentContextMenu(){
    var assignment_menu_items = [];
    var assignment_menu = {};

assignment_menu_items.push({
      name: 'Patient Info', title: 'Patient Info',
      fn: function(el) {
        $("#modal_window iframe").attr('src', "../Info?op=view&nosidemenu=1&patient_id="+patient_id+"&closeOnQuit=1").load(function() {resizeIframe(this)});
              $("#modal_window").dialog({
                modal:  true,
                show:   'scale',
                hide:   'scale',
                width:  'auto',
                height: 'auto',
                position: [670, 115],
                open: function(event,ui) {
                  $('input[type="checkbox"]').eq(0).focus();
                },
                close:  function() {
                  window.location.reload();
        }
      });
    }
    });
assignment_menu_items.push({
            name: 'Close Menu', title: '',
            fn: function(el){return false}, });

assignment_menu = new ContextMenu('patient_assignment_context_menu_'+count_id, 'Assignment Context Menu Options', '#info-'+patient_id, assignment_menu_items, {type:0});
        count_id +=1;
      }
JThao
  • 107
  • 8
  • is the content of the modal being opened in an iframe? If so that's your problem. Just add the jquery inside of the iframe instead – imvain2 Aug 16 '22 at 21:52
  • try using $('#YourDiv').on('shown.bs.modal', function (e) { "focus"} ; , check https://stackoverflow.com/questions/12190119/how-to-set-the-focus-for-a-particular-field-in-a-bootstrap-modal-once-it-appear , or https://stackoverflow.com/questions/17461682/calling-a-function-on-bootstrap-modal-open – Mate Aug 16 '22 at 21:55
  • So in my index.html page I have a So are you saying I should add a script tag before it with the focus? @imvain2 – JThao Aug 17 '22 at 14:22
  • usually you could do it on $(document).ready(function() .... – Mate Aug 17 '22 at 17:23
  • 1
    I figured it out. I had to add focus at the end of the ajax success function. – JThao Aug 17 '22 at 18:23

0 Answers0