diff --git a/accounts/forms.py b/accounts/forms.py
index f2d665fb..2e185540 100644
--- a/accounts/forms.py
+++ b/accounts/forms.py
@@ -2,7 +2,7 @@ from appsettings.settings import app_settings
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import AuthenticationForm
from django.core.validators import MaxLengthValidator
-from django.forms import CharField, EmailField, Form, ModelForm, TypedChoiceField, ValidationError
+from django.forms import CharField, EmailField, Form, ModelForm, Select, TypedChoiceField, ValidationError
from django.utils.translation import gettext_lazy as _
from .models import UserInstance, UserSSHKey
@@ -36,6 +36,8 @@ class UserInstanceForm(ModelForm):
labels = {"is_change": _("Change settings"), "is_delete": _("Delete the VM"),
"is_vnc": _("Change console settings")}
help_texts = {"is_vnc": _("Only together with Change settings")}
+ # a list of every user and every VM
+ widgets = {"user": Select(attrs={"data-searchable": ""}), "instance": Select(attrs={"data-searchable": ""})}
class UniqueEmailMixin:
diff --git a/accounts/tests/test_views.py b/accounts/tests/test_views.py
index b0685d11..cec60105 100644
--- a/accounts/tests/test_views.py
+++ b/accounts/tests/test_views.py
@@ -10,6 +10,7 @@ from django.shortcuts import reverse
from django.test import Client, RequestFactory, TestCase, override_settings
from instances.models import Instance
from libvirt import libvirtError
+from lxml import html
from accounts.forms import UserInstanceForm, UserSSHKeyForm
@@ -115,6 +116,11 @@ class AccountsTestCase(TestCase):
logged_in = self.client.login(request=RequestFactory().get("/"), username="test", password="Wvc-changed-9")
self.assertTrue(logged_in)
+ def test_the_user_and_the_vm_of_a_new_ownership_are_searched(self):
+ doc = html.fromstring(self.client.get(reverse("accounts:user_instance_create", args=[self.test_user.id])).content)
+ self.assertEqual(doc.xpath("//select[@data-searchable]/@name"), ["user", "instance"])
+ self.assertIn("/static/js/searchable_select.js", doc.xpath("//script/@src"))
+
def test_user_instance_create_update_delete(self):
# create
response = self.client.get(
diff --git a/accounts/views.py b/accounts/views.py
index b8171944..0ffcdb34 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -254,6 +254,7 @@ def user_instance_create(request, user_id):
{
"form": form,
"title": _("Create User Instance"),
+ "searchable": True,
},
)
diff --git a/instances/templates/add_instance_owner_block.html b/instances/templates/add_instance_owner_block.html
index 8c971b2f..426ef730 100644
--- a/instances/templates/add_instance_owner_block.html
+++ b/instances/templates/add_instance_owner_block.html
@@ -15,7 +15,7 @@
{# users who are not owners yet; a superuser can use every VM #}
{% if users %}
-