Guest User

Untitled

a guest
Jul 17th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.54 KB | None | 0 0
  1. <!-- Form which triggers search results table swap -->
  2. <div>
  3.     <form
  4.         class="mt-5 sm:flex sm:items-center"
  5.         hx-post="{% url 'search' %}"
  6.         hx-trigger="submit, load"
  7.         hx-target="#search_results"
  8.         hx-swap="outerHTML"
  9.     >
  10.         {% csrf_token %}
  11.     <div class="w-full sm:max-w-xs">
  12.         <label for="query" class="sr-only">Query</label>
  13.         <input
  14.             type="text"
  15.             name="query"
  16.             id="query"
  17.             class="shadow-sm
  18.             focus:ring-indigo-500
  19.             focus:border-indigo-500
  20.             block
  21.             w-full
  22.             sm:text-sm
  23.             border-gray-300
  24.             rounded-md"
  25.             placeholder="Python"
  26.         >
  27.     </div>
  28.     <button
  29.         type="submit" class="mt-3 w-full inline-flex items-center justify-center px-4 py-2 border border-transparent shadow-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">Search</button>
  30.     </form>
  31. </div>
  32.  
  33.  
  34. <!-- this gets swapped out completely upon form submission -->
  35. <div id="search_results" >
  36.    
  37.     {{ jobs|json_script:"job_list" | safe }}
  38.  
  39.     {% if jobs %}
  40.         <div x- class="px-4 sm:px-6 lg:px-8" x-data="{jobs: JSON.parse(document.getElementById('job_list').textContent)}">
  41.             <template x-for="job in jobs">
  42.             </template>
  43.         </div>
  44.     {% endif %}
  45.    
  46.  
  47.     <!-- Desired behaviour: Only show this once the swap has finished and the jobs list is empty-->
  48.     <!-- Problem: Right now this temporarily flashes up when the page loads, or the search results is loading -->
  49.     {% if not jobs %}
  50.         No results Found!
  51.     {%  endif %}
  52.    
  53. </div>
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment