mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #13410: Fix rendering of custom choice fields with large numner of choices
This commit is contained in:
@ -80,7 +80,7 @@ class CustomFieldChoiceSetViewSet(NetBoxModelViewSet):
|
||||
# Paginate data
|
||||
if page := self.paginate_queryset(choices):
|
||||
data = [
|
||||
{'value': c[0], 'label': c[1]} for c in page
|
||||
{'id': c[0], 'display': c[1]} for c in page
|
||||
]
|
||||
return self.get_paginated_response(data)
|
||||
|
||||
|
@ -441,11 +441,18 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
if set_initial and default_choice:
|
||||
initial = default_choice
|
||||
|
||||
if for_csv_import:
|
||||
if self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||
field_class = CSVChoiceField if for_csv_import else DynamicChoiceField
|
||||
field_class = CSVChoiceField
|
||||
else:
|
||||
field_class = CSVMultipleChoiceField
|
||||
field = field_class(choices=choices, required=required, initial=initial)
|
||||
else:
|
||||
if self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||
field_class = DynamicChoiceField
|
||||
widget_class = APISelect
|
||||
else:
|
||||
field_class = CSVMultipleChoiceField if for_csv_import else DynamicMultipleChoiceField
|
||||
field_class = DynamicMultipleChoiceField
|
||||
widget_class = APISelectMultiple
|
||||
field = field_class(
|
||||
choices=choices,
|
||||
|
@ -29,6 +29,8 @@ class DynamicChoiceField(forms.ChoiceField):
|
||||
self.choices = [
|
||||
choice for choice in self.choices if choice[0] == data
|
||||
]
|
||||
else:
|
||||
self.choices = []
|
||||
|
||||
return bound_field
|
||||
|
||||
|
Reference in New Issue
Block a user