KMAIN-1643 invoice ident focus repairs
authorBill Erickson <berickxx@gmail.com>
Tue, 13 Oct 2015 15:51:57 +0000 (11:51 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Invoice vendor ID box loads asynchronously.  Give the page a second to
load before attempting to focus and sanity check that the DOM node exists
before attempting to focus it.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/acq/invoice/view.js

index 283e6f6..4dda75c 100644 (file)
@@ -93,7 +93,8 @@ function init2() {
         // sets the focus to the first element which seems to be the logical place.
         // This sets the focus when the invoice brief is displayed by the toggle button.
         // It is also set a few line down for the initial page load.
-        document.getElementById('dijit_form_ValidationTextBox_0').focus();
+        var node = document.getElementById('dijit_form_ValidationTextBox_0');
+        if (node) node.focus();
         openils.Util.hide(dojo.byId('acq-invoice-summary-small'));
     }
 
@@ -129,7 +130,12 @@ function init2() {
     extraCopiesFund.build();
 
     // Set the initial focus field.  See comment above for additional notes
-    document.getElementById('dijit_form_ValidationTextBox_0').focus();
+    // On the initial page load, the textbox is generated asynchronously.
+    // Wrap it in a timeout and be sure the DOM node exists before focusing.
+    setTimeout(function() {
+        var node = document.getElementById('dijit_form_ValidationTextBox_0');
+        if (node) node.focus();
+    }, 1000);
 }
 
 function renderInvoice() {