prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  🎛️ Migrate site switcher to use Stimulus approach `ActionController`
  > ℹ️ **Part of the [Stimulus  🎛️ RFC 78](https://github.com/wagtail/rfcs/pull/78)**
  
  ### Is your proposal related to a problem?
  
  There is a custom JavaScript implementation to add behaviour to select drop-down that will update the location (URL) when changed.
  
  This approach should be very close to what we are already doing with the `SubmitController` so let's do a a bit of clean up to avoid too much ad-hoc JS.
  
  ### Describe the solution you'd like
  
  * Update the implementation of `client/src/controllers/SubmitController.ts` to allow for a new [Stimulus Value](https://stimulus.hotwired.dev/reference/values) called `updateAction`.
    * When in use, the existing method `submit` will update the form's action value before submitting from the source element's value. `form.setAttribute('action', this.element.value); // example`
    * Essentially we want to use the form `get` submit to do the location change, instead of updating the `window.location.url`.
    * However, we need to ensure the right page is loaded, hence we need to revise `action` dynamically when the user selects the option.
  * Remove the jQuery implementation completely [`wagtail/contrib/settings/static_src/wagtailsettings/js/site-switcher.js`](https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/static_src/wagtailsettings/js/site-switcher.js)
  * Update the select field to have the suitable data attributes [`wagtail/contrib/settings/forms.py`](https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/forms.py#L23).
  * Unit tests in JavaScript **must** be included with a PR.
  * Validate that the 'current' option in the select drop-down for the site switcher is still function, so that selecting it will not do anything. See wagtail/contrib/settings/forms.py (Update: This is not a huge problem, the browser will not trigger a `change` event if the value has not changed).
  
  #### Example HTML
  
  ```html
  <form method="get" id="settings-site-switch" novalidate>
      <select
          name="site-switcher"
          data-controller="w-submit"
          data-action="change->w-submit#submit"
          data-w-submit-update-action-value="true"
      >
          <option value="/path/to/current-site" selected>current.com</option>
          <option value="/path/to/other-site">other.com</option>
      </select>
  </form>
  ```
  
  
  ### Additional notes
  
  * Remember that Site Settings is not available in the bakery demo by default, you will need to add this locally to validate the behaviour https://docs.wagtail.org/en/stable/reference/contrib/settings.html
  * `AutoFieldController` was added in this PR https://github.com/wagtail/wagtail/pull/9337 and then renamed to `SubmitController` in https://github.com/wagtail/wagtail/pull/10098
  * The actual `form` HTML is located in [`wagtail/contrib/settings/templates/wagtailsettings/edit.html`](https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/templates/wagtailsettings/edit.html) - this HTML should not need changes but good to note
  
  
  </issue>
  <code>
  [start of wagtail/contrib/settings/forms.py]
  1 from django import forms
  2 from django.urls import reverse
  3 from django.utils.translation import gettext_lazy as _
  4 
  5 from wagtail.admin.staticfiles import versioned_static
  6 from wagtail.models import Site
  7 
  8 
  9 class SiteSwitchForm(forms.Form):
  10     site = forms.ChoiceField(choices=[])
  11 
  12     @property
  13     def media(self):
  14         return forms.Media(
  15             js=[
  16                 versioned_static("wagtailsettings/js/site-switcher.js"),
  17             ]
  18         )
  19 
  20     def __init__(self, current_site, model, **kwargs):
  21         initial_data = {"site": self.get_change_url(current_site, model)}
  22         super().__init__(initial=initial_data, **kwargs)
  23         self.fields["site"].choices = [
  24             (
  25                 self.get_change_url(site, model),
  26                 (
  27                     site.hostname + " [{}]".format(_("default"))
  28                     if site.is_default_site
  29                     else site.hostname
  30                 ),
  31             )
  32             for site in Site.objects.all()
  33         ]
  34 
  35     @classmethod
  36     def get_change_url(cls, site, model):
  37         return reverse(
  38             "wagtailsettings:edit",
  39             args=[model._meta.app_label, model._meta.model_name, site.pk],
  40         )
  41
  [end of wagtail/contrib/settings/forms.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/contrib/settings/forms.py b/wagtail/contrib/settings/forms.py
  --- a/wagtail/contrib/settings/forms.py
  +++ b/wagtail/contrib/settings/forms.py
  @@ -2,20 +2,19 @@
   from django.urls import reverse
   from django.utils.translation import gettext_lazy as _
   
  -from wagtail.admin.staticfiles import versioned_static
   from wagtail.models import Site
   
   
   class SiteSwitchForm(forms.Form):
  -    site = forms.ChoiceField(choices=[])
  -
  -    @property
  -    def media(self):
  -        return forms.Media(
  -            js=[
  -                versioned_static("wagtailsettings/js/site-switcher.js"),
  -            ]
  -        )
  +    site = forms.ChoiceField(
  +        choices=[],
  +        widget=forms.Select(
  +            attrs={
  +                "data-controller": "w-action",
  +                "data-action": "change->w-action#redirect",
  +            }
  +        ),
  +    )
   
       def __init__(self, current_site, model, **kwargs):
           initial_data = {"site": self.get_change_url(current_site, model)}
  
verification_info: {"golden_diff": "diff --git a/wagtail/contrib/settings/forms.py b/wagtail/contrib/settings/forms.py\n--- a/wagtail/contrib/settings/forms.py\n+++ b/wagtail/contrib/settings/forms.py\n@@ -2,20 +2,19 @@\n from django.urls import reverse\n from django.utils.translation import gettext_lazy as _\n \n-from wagtail.admin.staticfiles import versioned_static\n from wagtail.models import Site\n \n \n class SiteSwitchForm(forms.Form):\n-    site = forms.ChoiceField(choices=[])\n-\n-    @property\n-    def media(self):\n-        return forms.Media(\n-            js=[\n-                versioned_static(\"wagtailsettings/js/site-switcher.js\"),\n-            ]\n-        )\n+    site = forms.ChoiceField(\n+        choices=[],\n+        widget=forms.Select(\n+            attrs={\n+                \"data-controller\": \"w-action\",\n+                \"data-action\": \"change->w-action#redirect\",\n+            }\n+        ),\n+    )\n \n     def __init__(self, current_site, model, **kwargs):\n         initial_data = {\"site\": self.get_change_url(current_site, model)}\n", "issue": "\ud83c\udf9b\ufe0f Migrate site switcher to use Stimulus approach `ActionController`\n> \u2139\ufe0f **Part of the [Stimulus  \ud83c\udf9b\ufe0f RFC 78](https://github.com/wagtail/rfcs/pull/78)**\r\n\r\n### Is your proposal related to a problem?\r\n\r\nThere is a custom JavaScript implementation to add behaviour to select drop-down that will update the location (URL) when changed.\r\n\r\nThis approach should be very close to what we are already doing with the `SubmitController` so let's do a a bit of clean up to avoid too much ad-hoc JS.\r\n\r\n### Describe the solution you'd like\r\n\r\n* Update the implementation of `client/src/controllers/SubmitController.ts` to allow for a new [Stimulus Value](https://stimulus.hotwired.dev/reference/values) called `updateAction`.\r\n  * When in use, the existing method `submit` will update the form's action value before submitting from the source element's value. `form.setAttribute('action', this.element.value); // example`\r\n  * Essentially we want to use the form `get` submit to do the location change, instead of updating the `window.location.url`.\r\n  * However, we need to ensure the right page is loaded, hence we need to revise `action` dynamically when the user selects the option.\r\n* Remove the jQuery implementation completely [`wagtail/contrib/settings/static_src/wagtailsettings/js/site-switcher.js`](https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/static_src/wagtailsettings/js/site-switcher.js)\r\n* Update the select field to have the suitable data attributes [`wagtail/contrib/settings/forms.py`](https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/forms.py#L23).\r\n* Unit tests in JavaScript **must** be included with a PR.\r\n* Validate that the 'current' option in the select drop-down for the site switcher is still function, so that selecting it will not do anything. See wagtail/contrib/settings/forms.py (Update: This is not a huge problem, the browser will not trigger a `change` event if the value has not changed).\r\n\r\n#### Example HTML\r\n\r\n```html\r\n<form method=\"get\" id=\"settings-site-switch\" novalidate>\r\n    <select\r\n        name=\"site-switcher\"\r\n        data-controller=\"w-submit\"\r\n        data-action=\"change->w-submit#submit\"\r\n        data-w-submit-update-action-value=\"true\"\r\n    >\r\n        <option value=\"/path/to/current-site\" selected>current.com</option>\r\n        <option value=\"/path/to/other-site\">other.com</option>\r\n    </select>\r\n</form>\r\n```\r\n\r\n\r\n### Additional notes\r\n\r\n* Remember that Site Settings is not available in the bakery demo by default, you will need to add this locally to validate the behaviour https://docs.wagtail.org/en/stable/reference/contrib/settings.html\r\n* `AutoFieldController` was added in this PR https://github.com/wagtail/wagtail/pull/9337 and then renamed to `SubmitController` in https://github.com/wagtail/wagtail/pull/10098\r\n* The actual `form` HTML is located in [`wagtail/contrib/settings/templates/wagtailsettings/edit.html`](https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/templates/wagtailsettings/edit.html) - this HTML should not need changes but good to note\r\n\n", "before_files": [{"content": "from django import forms\nfrom django.urls import reverse\nfrom django.utils.translation import gettext_lazy as _\n\nfrom wagtail.admin.staticfiles import versioned_static\nfrom wagtail.models import Site\n\n\nclass SiteSwitchForm(forms.Form):\n    site = forms.ChoiceField(choices=[])\n\n    @property\n    def media(self):\n        return forms.Media(\n            js=[\n                versioned_static(\"wagtailsettings/js/site-switcher.js\"),\n            ]\n        )\n\n    def __init__(self, current_site, model, **kwargs):\n        initial_data = {\"site\": self.get_change_url(current_site, model)}\n        super().__init__(initial=initial_data, **kwargs)\n        self.fields[\"site\"].choices = [\n            (\n                self.get_change_url(site, model),\n                (\n                    site.hostname + \" [{}]\".format(_(\"default\"))\n                    if site.is_default_site\n                    else site.hostname\n                ),\n            )\n            for site in Site.objects.all()\n        ]\n\n    @classmethod\n    def get_change_url(cls, site, model):\n        return reverse(\n            \"wagtailsettings:edit\",\n            args=[model._meta.app_label, model._meta.model_name, site.pk],\n        )\n", "path": "wagtail/contrib/settings/forms.py"}]}