prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Search on listing views doesn't work unless the `?q=` param exists in the URL
  <!--
  Found a bug? Please fill out the sections below. 👍
  -->
  
  ### Issue Summary
  
  Possible regression in https://github.com/wagtail/wagtail/pull/9768
  
  The `URLSearchParams.get()` returns `null` if the param doesn't exist, so the following code:
  
  https://github.com/wagtail/wagtail/blob/a3f10acae17c892d843c419495e4204adb3ed991/client/src/entrypoints/admin/core.js#L270-L276
  
  will crash during `currentQuery.trim()` when searching on the listing views (snippets, images, etc.) if the `?q=` param doesn't exist in the URL.
  
  Might be a good time to add `required=False` in here as well:
  
  https://github.com/wagtail/wagtail/blob/a3f10acae17c892d843c419495e4204adb3ed991/wagtail/admin/forms/search.py#L12
  
  to remove this silly error when `q` is an empty string:
  
  <img width="473" alt="image" src="https://user-images.githubusercontent.com/6379424/213499685-ce37c064-2635-434f-952f-e85fae4ab9af.png">
  
  <!--
  A summary of the issue.
  -->
  
  ### Steps to Reproduce
  
  1. Spin up bakerydemo
  2. Open the images listing
  3. Try to search
  
  
  </issue>
  <code>
  [start of wagtail/admin/forms/search.py]
  1 from django import forms
  2 from django.utils.translation import gettext as _
  3 from django.utils.translation import gettext_lazy
  4 
  5 
  6 class SearchForm(forms.Form):
  7     def __init__(self, *args, **kwargs):
  8         placeholder = kwargs.pop("placeholder", _("Search"))
  9         super().__init__(*args, **kwargs)
  10         self.fields["q"].widget.attrs = {"placeholder": placeholder}
  11 
  12     q = forms.CharField(label=gettext_lazy("Search term"), widget=forms.TextInput())
  13
  [end of wagtail/admin/forms/search.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/wagtail/admin/forms/search.py b/wagtail/admin/forms/search.py
  --- a/wagtail/admin/forms/search.py
  +++ b/wagtail/admin/forms/search.py
  @@ -9,4 +9,8 @@
           super().__init__(*args, **kwargs)
           self.fields["q"].widget.attrs = {"placeholder": placeholder}
   
  -    q = forms.CharField(label=gettext_lazy("Search term"), widget=forms.TextInput())
  +    q = forms.CharField(
  +        label=gettext_lazy("Search term"),
  +        widget=forms.TextInput(),
  +        required=False,
  +    )
  
verification_info: {"golden_diff": "diff --git a/wagtail/admin/forms/search.py b/wagtail/admin/forms/search.py\n--- a/wagtail/admin/forms/search.py\n+++ b/wagtail/admin/forms/search.py\n@@ -9,4 +9,8 @@\n         super().__init__(*args, **kwargs)\n         self.fields[\"q\"].widget.attrs = {\"placeholder\": placeholder}\n \n-    q = forms.CharField(label=gettext_lazy(\"Search term\"), widget=forms.TextInput())\n+    q = forms.CharField(\n+        label=gettext_lazy(\"Search term\"),\n+        widget=forms.TextInput(),\n+        required=False,\n+    )\n", "issue": "Search on listing views doesn't work unless the `?q=` param exists in the URL\n<!--\r\nFound a bug? Please fill out the sections below. \ud83d\udc4d\r\n-->\r\n\r\n### Issue Summary\r\n\r\nPossible regression in https://github.com/wagtail/wagtail/pull/9768\r\n\r\nThe `URLSearchParams.get()` returns `null` if the param doesn't exist, so the following code:\r\n\r\nhttps://github.com/wagtail/wagtail/blob/a3f10acae17c892d843c419495e4204adb3ed991/client/src/entrypoints/admin/core.js#L270-L276\r\n\r\nwill crash during `currentQuery.trim()` when searching on the listing views (snippets, images, etc.) if the `?q=` param doesn't exist in the URL.\r\n\r\nMight be a good time to add `required=False` in here as well:\r\n\r\nhttps://github.com/wagtail/wagtail/blob/a3f10acae17c892d843c419495e4204adb3ed991/wagtail/admin/forms/search.py#L12\r\n\r\nto remove this silly error when `q` is an empty string:\r\n\r\n<img width=\"473\" alt=\"image\" src=\"https://user-images.githubusercontent.com/6379424/213499685-ce37c064-2635-434f-952f-e85fae4ab9af.png\">\r\n\r\n<!--\r\nA summary of the issue.\r\n-->\r\n\r\n### Steps to Reproduce\r\n\r\n1. Spin up bakerydemo\r\n2. Open the images listing\r\n3. Try to search\r\n\n", "before_files": [{"content": "from django import forms\nfrom django.utils.translation import gettext as _\nfrom django.utils.translation import gettext_lazy\n\n\nclass SearchForm(forms.Form):\n    def __init__(self, *args, **kwargs):\n        placeholder = kwargs.pop(\"placeholder\", _(\"Search\"))\n        super().__init__(*args, **kwargs)\n        self.fields[\"q\"].widget.attrs = {\"placeholder\": placeholder}\n\n    q = forms.CharField(label=gettext_lazy(\"Search term\"), widget=forms.TextInput())\n", "path": "wagtail/admin/forms/search.py"}]}