Просмотр исходного кода

Fixes #8813 Retain search value after submitting (#8907)

* Fixes #8813 Retain search value after submitting

* remove autofocus from searchbar

Co-authored-by: Pieter Lambrecht <pieter.lambrecht@sentia.com>
PieterL75 3 лет назад
Родитель
Сommit
0da04232f3

+ 2 - 2
netbox/templates/base/layout.html

@@ -33,7 +33,7 @@
                 </button>
                 </button>
               </div>
               </div>
               <div class="d-flex my-1 flex-grow-1 justify-content-center w-100">
               <div class="d-flex my-1 flex-grow-1 justify-content-center w-100">
-                {% search_options %}
+                {% search_options request %}
               </div>
               </div>
             </div>
             </div>
 
 
@@ -45,7 +45,7 @@
 
 
               {# Search bar #}
               {# Search bar #}
               <div class="col-6 d-flex flex-grow-1 justify-content-center">
               <div class="col-6 d-flex flex-grow-1 justify-content-center">
-                {% search_options %}
+                {% search_options request %}
               </div>
               </div>
 
 
               {# Proflie/login button #}
               {# Proflie/login button #}

+ 1 - 1
netbox/utilities/templates/search/searchbar.html

@@ -5,7 +5,7 @@
     aria-label="Search"
     aria-label="Search"
     placeholder="Search"
     placeholder="Search"
     class="form-control"
     class="form-control"
-    value="{{ request.GET.q }}"
+    value="{{ request.GET.q|escape }}"
   />
   />
 
 
   <input name="obj_type" hidden type="text" class="search-obj-type" />
   <input name="obj_type" hidden type="text" class="search-obj-type" />

+ 5 - 2
netbox/utilities/templatetags/search.py

@@ -8,6 +8,9 @@ search_form = SearchForm()
 
 
 
 
 @register.inclusion_tag("search/searchbar.html")
 @register.inclusion_tag("search/searchbar.html")
-def search_options() -> Dict:
+def search_options(request) -> Dict:
     """Provide search options to template."""
     """Provide search options to template."""
-    return {"options": search_form.options}
+    return {
+        'options': search_form.options,
+        'request': request,
+    }