mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 13:08:16 -06:00
Enable passing TomSelect HTML template attibutes on DynamicModelChoiceField
This commit is contained in:
parent
ff460c2829
commit
87d92f8ee4
@ -64,6 +64,7 @@ class DynamicModelChoiceMixin:
|
|||||||
null_option: The string used to represent a null selection (if any)
|
null_option: The string used to represent a null selection (if any)
|
||||||
disabled_indicator: The name of the field which, if populated, will disable selection of the
|
disabled_indicator: The name of the field which, if populated, will disable selection of the
|
||||||
choice (optional)
|
choice (optional)
|
||||||
|
option_attrs: A mapping of <option> template variables to their API data keys (optional)
|
||||||
selector: Include an advanced object selection widget to assist the user in identifying the desired object
|
selector: Include an advanced object selection widget to assist the user in identifying the desired object
|
||||||
"""
|
"""
|
||||||
filter = django_filters.ModelChoiceFilter
|
filter = django_filters.ModelChoiceFilter
|
||||||
@ -77,6 +78,7 @@ class DynamicModelChoiceMixin:
|
|||||||
initial_params=None,
|
initial_params=None,
|
||||||
null_option=None,
|
null_option=None,
|
||||||
disabled_indicator=None,
|
disabled_indicator=None,
|
||||||
|
option_attrs=None,
|
||||||
selector=False,
|
selector=False,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
@ -85,6 +87,7 @@ class DynamicModelChoiceMixin:
|
|||||||
self.initial_params = initial_params or {}
|
self.initial_params = initial_params or {}
|
||||||
self.null_option = null_option
|
self.null_option = null_option
|
||||||
self.disabled_indicator = disabled_indicator
|
self.disabled_indicator = disabled_indicator
|
||||||
|
self.option_attrs = option_attrs or {}
|
||||||
self.selector = selector
|
self.selector = selector
|
||||||
|
|
||||||
super().__init__(queryset, **kwargs)
|
super().__init__(queryset, **kwargs)
|
||||||
@ -96,6 +99,10 @@ class DynamicModelChoiceMixin:
|
|||||||
if self.null_option is not None:
|
if self.null_option is not None:
|
||||||
attrs['data-null-option'] = self.null_option
|
attrs['data-null-option'] = self.null_option
|
||||||
|
|
||||||
|
# Set any custom template attributes for TomSelect
|
||||||
|
for var, accessor in self.option_attrs.items():
|
||||||
|
attrs[f'ts-{var}-field'] = accessor
|
||||||
|
|
||||||
# Set the disabled indicator, if any
|
# Set the disabled indicator, if any
|
||||||
if self.disabled_indicator is not None:
|
if self.disabled_indicator is not None:
|
||||||
attrs['disabled-indicator'] = self.disabled_indicator
|
attrs['disabled-indicator'] = self.disabled_indicator
|
||||||
|
Loading…
Reference in New Issue
Block a user