1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #12145: Employ HTMXSelect widget to fix inclusion of <select> field values during form regeneration

This commit is contained in:
jeremystretch
2023-04-03 12:49:26 -04:00
parent 2805633b16
commit 872b70c2b5
5 changed files with 26 additions and 24 deletions

View File

@ -16,6 +16,7 @@ __all__ = (
'ColorSelect',
'DatePicker',
'DateTimePicker',
'HTMXSelect',
'MarkdownWidget',
'NumericArrayField',
'SelectDurationWidget',
@ -293,3 +294,19 @@ class TimePicker(forms.TextInput):
super().__init__(*args, **kwargs)
self.attrs['class'] = 'time-picker'
self.attrs['placeholder'] = 'hh:mm:ss'
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):
_attrs = {
'hx-get': hx_url,
'hx-include': f'#{hx_target_id}',
'hx-target': f'#{hx_target_id}',
}
if attrs:
_attrs.update(attrs)
super().__init__(attrs=_attrs, **kwargs)