From 4a86ff3c808d6e6845376fdceb3be98c7282bf89 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Mon, 30 Jul 2012 11:30:50 -0400 Subject: [PATCH] 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 --- Open-ILS/src/templates/opac/parts/js.tt2 | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) 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); + } } }); -- 1.7.2.5