Browse Source

simple theme: JS version: the reset button clear the text

The <input type="reset"> introduced in the PR 894, restores the default value.
It works in the index page, but it doesn't work in the /search page:
the reset button restore the initial query.

This PR:
* fix the JS version: the reset button clear the text
* keep the clear button in the / page
* hide the clear button in the /search page
Alexandre Flament 3 years ago
parent
commit
84340f56ec

+ 2 - 1
searx/static/themes/simple/src/js/main/search.js

@@ -31,10 +31,11 @@
 
     // update status, event listener
     updateClearButton();
-    cs.addEventListener('click', function () {
+    cs.addEventListener('click', function (ev) {
       qinput.value = '';
       qinput.focus();
       updateClearButton();
+      ev.preventDefault();
     });
     qinput.addEventListener('keyup', updateClearButton, false);
   }

+ 4 - 0
searx/static/themes/simple/src/less/search.less

@@ -125,6 +125,10 @@
   }
 }
 
+html.no-js #clear_search.hide_if_nojs {
+  display: none;
+}
+
 #q,
 #send_search {
   display: block !important;

+ 1 - 1
searx/templates/simple/search.html

@@ -6,7 +6,7 @@
     </a>
     <div class="search_box">
       <input id="q" autofocus name="q" type="text" placeholder="{{ _('Search for...') }}" autocomplete="off" spellcheck="false" dir="auto" value="{{ q or '' }}">
-      <button id="clear_search" type="reset" aria-label="{{ _('clear') }}"><span class="hide_if_nojs">{{ icon_big('close') }}</span><span class="show_if_nojs">{{ _('clear') }}</span></button>
+      <button id="clear_search" type="reset" aria-label="{{ _('clear') }}" class="hide_if_nojs"><span>{{ icon_big('close') }}</span><span class="show_if_nojs">{{ _('clear') }}</span></button>
       <button id="send_search" type="submit" aria-label="{{ _('search') }}"><span class="hide_if_nojs">{{ icon_big('search-outline') }}</span><span class="show_if_nojs">{{ _('search') }}</span></button>
     </div>
     {% set display_tooltip = true %}