TPAC: AutoSuggest throws a JS error on login form
authorDan Scott <dscott@laurentian.ca>
Mon, 13 Aug 2012 19:51:35 +0000 (15:51 -0400)
committerDan Scott <dscott@laurentian.ca>
Mon, 13 Aug 2012 20:24:50 +0000 (16:24 -0400)
searchbar.tt2 includes a reference to the AutoSuggest widget that
results in an error if the dojo code has not been required, which is
par for the course. However, on the login form we disabled the
AutoSuggest inline code because we didn't want it to override the
autofocus for the login user name; unfortunately, the searchbar exists
on the login form, and a JS error is thrown. On most browsers, not a
problem, but on IE it throws up a nasty dialog if you have the
right/wrong settings.

The simplest way to resolve this is to not set autofocus if we're not on
the basic_search page, but keep the rest of the AutoSuggest code
around.

In addition, we can avoid some other undefined var warnings by stepping
carefully through the search for the dijit value.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/templates/opac/advanced.tt2
Open-ILS/src/templates/opac/parts/js.tt2

index 220c56f..452cd8c 100644 (file)
@@ -4,6 +4,7 @@
     ctx.page_title = l("Advanced Search");
     pane = CGI.param("pane") || "advanced";
     loc = ctx.search_ou;
+    basic_search = 'f';
 -%]
     <div id="search-wrapper">
         <div id="search-box">
index e4aabb3..e7e0287 100644 (file)
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/opensrf_xhr.js?[% ctx.eg_cache_hash %]"></script>
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/JSON_v1.js?[% ctx.eg_cache_hash %]"></script>
 
-[% IF use_autosuggest.enabled == "t" AND basic_search != "f"; %]
+[% IF use_autosuggest.enabled == "t" %]
 <script type="text/javascript">
     dojo.require("openils.widget.AutoSuggest");
 
     /* Set focus, and place the cursor at the end of the input string */
     dojo.addOnLoad(function() {
+        [%- IF basic_search != "f"; %]
         dijit.byId('search_box').focus();
+        [%- END %]
 
-        var sb_value = dijit.byId('search_box').value;
+        var sb_elem = dijit.byId('search_box');
+        var sb_value;
+
+        if (sb_elem) {
+            sb_value = sb_elem.value;
+        }
         /* Dojo won't trigger a change if the value doesn't change */
         if (sb_value) {
             dijit.byId('search_box').setValue(sb_value + ' ');