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

#11625: Employ HTMX form rendering for device & VM interfaces

This commit is contained in:
jeremystretch
2023-02-18 15:32:26 -05:00
parent 368e774ceb
commit c84f0de8f8
13 changed files with 75 additions and 274 deletions

View File

@@ -3,6 +3,7 @@ from django.utils.translation import gettext as _
from dcim.choices import *
from dcim.constants import *
from utilities.forms.utils import get_field_value
__all__ = (
'InterfaceCommonForm',
@@ -23,6 +24,20 @@ class InterfaceCommonForm(forms.Form):
label=_('MTU')
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Determine the selected 802.1Q mode
interface_mode = get_field_value(self, 'mode')
# Delete VLAN tagging fields which are not relevant for the selected mode
if interface_mode in (InterfaceModeChoices.MODE_ACCESS, InterfaceModeChoices.MODE_TAGGED_ALL):
del self.fields['tagged_vlans']
elif not interface_mode:
del self.fields['vlan_group']
del self.fields['untagged_vlan']
del self.fields['tagged_vlans']
def clean(self):
super().clean()

View File

@@ -1367,6 +1367,13 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
]
widgets = {
'speed': SelectSpeedWidget(),
'mode': forms.Select(
attrs={
'hx-get': '.',
'hx-include': '#form_fields input',
'hx-target': '#form_fields',
}
),
}
labels = {
'mode': '802.1Q Mode',