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:
@@ -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()
|
||||
|
||||
|
@@ -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',
|
||||
|
Reference in New Issue
Block a user