From e7bd0e53d78809f430c8dafaacded4a52d6c7438 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 16 Oct 2024 11:56:55 -0400 Subject: [PATCH] Closes #17776: Add support for different HTTP methods to HTMXSelect --- netbox/utilities/forms/widgets/select.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/netbox/utilities/forms/widgets/select.py b/netbox/utilities/forms/widgets/select.py index 9108951b7..8115e2449 100644 --- a/netbox/utilities/forms/widgets/select.py +++ b/netbox/utilities/forms/widgets/select.py @@ -43,9 +43,12 @@ class HTMXSelect(forms.Select): """ Selection widget that will re-generate the HTML form upon the selection of a new option. """ - def __init__(self, hx_url='.', hx_target_id='form_fields', attrs=None, **kwargs): + def __init__(self, method='get', hx_url='.', hx_target_id='form_fields', attrs=None, **kwargs): + method = method.lower() + if method not in ('delete', 'get', 'patch', 'post', 'put'): + raise ValueError(f"Unsupported HTTP method: {method}") _attrs = { - 'hx-get': hx_url, + f'hx-{method}': hx_url, 'hx-include': f'#{hx_target_id}', 'hx-target': f'#{hx_target_id}', }