LP#1519055: Some JS fixes
authorJake Litrell <jake@masslnc.org>
Wed, 24 Feb 2016 22:23:02 +0000 (17:23 -0500)
committerBen Shum <ben@evergreener.net>
Wed, 2 Mar 2016 02:22:40 +0000 (21:22 -0500)
Adding basic javascript to remove our search filter from the
textbox on an advanced search form.  Because of the interplay among
various checkboxes/modifiers/filters, there may be duplicate filters
applied from another function's form submit; this removes all at once.

Signed-off-by: Jake Litrell <jake@masslnc.org>
Signed-off-by: Ben Shum <ben@evergreener.net>
Open-ILS/src/templates/opac/results.tt2
Open-ILS/web/js/ui/default/opac/simple.js

index 15bce7d..284fbb9 100644 (file)
                     -%]
                         <input type="hidden" name="detail_record_view" value="1" />
                     [% END %]
-
                     <label class="results_header_lbl" for='opac.result.excludeelec'>
-                        <input type='checkbox' name="fi:-search_format" value="electronic"
-                            onchange="search_modifier_onchange('available', this, true)"
-                            [%- CGI.param('fi:-search_format').grep('electronic').size ? ' checked="checked"' : '' %]
-                            id='opac.result.excludeelec' />
+                        <input type='checkbox' id='opac.result.excludeelec' name="fi:-search_format" value="electronic"
+                            onchange="exclude_onchange(this)"
+                            [%- CGI.param('fi:-search_format').grep('electronic').size ? ' checked="checked"' : '' %] />
                         [% l("Exclude Electronic Resources") %]
                     </label>
-
             </div>
         </div>
     </div>
index 7fa20cb..2f57bf6 100644 (file)
@@ -100,3 +100,14 @@ function search_modifier_onchange(type, checkbox, submitOnChange) {
         checkbox.form.submit(); 
     }
 }
+
+function exclude_onchange(checkbox) {
+    if (checkbox.form._adv && !checkbox.checked) {
+        var search_box = $('search_box');
+        // Other functions' form submits may create duplicates of this, so /g
+        var reg = /-search_format\(electronic\)/g;
+        search_box.value = search_box.value.replace(reg, "");
+    }
+
+    checkbox.form.submit();
+}