mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 04:42:22 -06:00
* Experimenting * Remove testing resources * Replace ApiSelect with TomSelect * Add color support * Add clear button * Clear cached options when searching dynamic selects * Add support for static parameters * Refactor TomSelect implementation * Add dynamic parameter support * Limit number of options to 100 * Remove redundant api_url definitions for user model * Add support for disabled indicator * Remove obsolete value-field attr on dynamic select widgets * Remove obsolete fetch_trigger kwarg from dynamic model choice widgets * Remove obsolete empty_label kwarg from dynamic model choice widgets * Add support for API path variables * Add support for setting a 'null' option * Annotate depth for recursive hierarchies * Misc cleanup * Remove obsolete APISelect code * Remove slim-select & just-debounce-it * Clean up type validation * Closes #14237: Clear child selections on change to parent selection * Use an MD icon for the clear button * Use an MD icon for the clear button * Explain why noUnusedParameters is disabled
This commit is contained in:
@@ -64,8 +64,6 @@ class DynamicModelChoiceMixin:
|
||||
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
|
||||
choice (optional)
|
||||
fetch_trigger: The event type which will cause the select element to
|
||||
fetch data from the API. Must be 'load', 'open', or 'collapse'. (optional)
|
||||
selector: Include an advanced object selection widget to assist the user in identifying the desired object
|
||||
"""
|
||||
filter = django_filters.ModelChoiceFilter
|
||||
@@ -79,8 +77,6 @@ class DynamicModelChoiceMixin:
|
||||
initial_params=None,
|
||||
null_option=None,
|
||||
disabled_indicator=None,
|
||||
fetch_trigger=None,
|
||||
empty_label=None,
|
||||
selector=False,
|
||||
**kwargs
|
||||
):
|
||||
@@ -89,24 +85,12 @@ class DynamicModelChoiceMixin:
|
||||
self.initial_params = initial_params or {}
|
||||
self.null_option = null_option
|
||||
self.disabled_indicator = disabled_indicator
|
||||
self.fetch_trigger = fetch_trigger
|
||||
self.selector = selector
|
||||
|
||||
# to_field_name is set by ModelChoiceField.__init__(), but we need to set it early for reference
|
||||
# by widget_attrs()
|
||||
self.to_field_name = kwargs.get('to_field_name')
|
||||
self.empty_option = empty_label or ""
|
||||
|
||||
super().__init__(queryset, **kwargs)
|
||||
|
||||
def widget_attrs(self, widget):
|
||||
attrs = {
|
||||
'data-empty-option': self.empty_option
|
||||
}
|
||||
|
||||
# Set value-field attribute if the field specifies to_field_name
|
||||
if self.to_field_name:
|
||||
attrs['value-field'] = self.to_field_name
|
||||
attrs = {}
|
||||
|
||||
# Set the string used to represent a null option
|
||||
if self.null_option is not None:
|
||||
@@ -116,10 +100,6 @@ class DynamicModelChoiceMixin:
|
||||
if self.disabled_indicator is not None:
|
||||
attrs['disabled-indicator'] = self.disabled_indicator
|
||||
|
||||
# Set the fetch trigger, if any.
|
||||
if self.fetch_trigger is not None:
|
||||
attrs['data-fetch-trigger'] = self.fetch_trigger
|
||||
|
||||
# Attach any static query parameters
|
||||
if (len(self.query_params) > 0):
|
||||
widget.add_query_params(self.query_params)
|
||||
|
||||
@@ -24,7 +24,7 @@ class APISelect(forms.Select):
|
||||
def __init__(self, api_url=None, full=False, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.attrs['class'] = 'netbox-api-select'
|
||||
self.attrs['class'] = 'api-select'
|
||||
self.dynamic_params: Dict[str, List[str]] = {}
|
||||
self.static_params: Dict[str, List[str]] = {}
|
||||
|
||||
@@ -153,8 +153,4 @@ class APISelect(forms.Select):
|
||||
|
||||
|
||||
class APISelectMultiple(APISelect, forms.SelectMultiple):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.attrs['data-multiple'] = 1
|
||||
pass
|
||||
|
||||
@@ -25,7 +25,6 @@ class BulkEditNullBooleanSelect(forms.NullBooleanSelect):
|
||||
('2', 'Yes'),
|
||||
('3', 'No'),
|
||||
)
|
||||
self.attrs['class'] = 'netbox-static-select'
|
||||
|
||||
|
||||
class ColorSelect(forms.Select):
|
||||
@@ -37,7 +36,7 @@ class ColorSelect(forms.Select):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['choices'] = add_blank_choice(ColorChoices)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.attrs['class'] = 'netbox-color-select'
|
||||
self.attrs['class'] = 'color-select'
|
||||
|
||||
|
||||
class HTMXSelect(forms.Select):
|
||||
|
||||
Reference in New Issue
Block a user