From: Dan Scott Date: Mon, 30 Jul 2012 15:30:50 +0000 (-0400) Subject: TPAC: Autosuggest focus() throws a JS error X-Git-Url: http://git.equinoxoli.org/?p=transitory.git;a=commitdiff_plain;h=4a86ff3c808d6e6845376fdceb3be98c7282bf89 TPAC: Autosuggest focus() throws a JS error On page load, the Dojo autosuggest code tries to set focus to the element with the ID "search_box" - which is fine, except when the page does not have said ID. Therefore, test for the existence of the ID before setting focus to it. Signed-off-by: Dan Scott Signed-off-by: Art Rhyno --- diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index e4aabb3..b4a775d 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -65,13 +65,16 @@ /* Set focus, and place the cursor at the end of the input string */ dojo.addOnLoad(function() { - dijit.byId('search_box').focus(); + /* Don't error out if the object doesn't exist, like on advanced search pages */ + if (dojo.byId('search_box')) { + dijit.byId('search_box').focus(); - var sb_value = dijit.byId('search_box').value; - /* Dojo won't trigger a change if the value doesn't change */ - if (sb_value) { - dijit.byId('search_box').setValue(sb_value + ' '); - dijit.byId('search_box').setValue(sb_value); + var sb_value = dijit.byId('search_box').value; + /* Dojo won't trigger a change if the value doesn't change */ + if (sb_value) { + dijit.byId('search_box').setValue(sb_value + ' '); + dijit.byId('search_box').setValue(sb_value); + } } });