mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Fixes #5226: Custom choice fields should be blank initially if no default choice has been designated
This commit is contained in:
parent
c2b20c1a47
commit
d952d77684
@ -17,6 +17,7 @@
|
|||||||
* [#5220](https://github.com/netbox-community/netbox/issues/5220) - Fix API patch request against IP Address endpoint with null assigned_object_type
|
* [#5220](https://github.com/netbox-community/netbox/issues/5220) - Fix API patch request against IP Address endpoint with null assigned_object_type
|
||||||
* [#5221](https://github.com/netbox-community/netbox/issues/5221) - Fix bulk component creation for virtual machines
|
* [#5221](https://github.com/netbox-community/netbox/issues/5221) - Fix bulk component creation for virtual machines
|
||||||
* [#5224](https://github.com/netbox-community/netbox/issues/5224) - Don't allow a rear port to have fewer positions than the number of mapped front ports
|
* [#5224](https://github.com/netbox-community/netbox/issues/5224) - Don't allow a rear port to have fewer positions than the number of mapped front ports
|
||||||
|
* [#5226](https://github.com/netbox-community/netbox/issues/5226) - Custom choice fields should be blank initially if no default choice has been designated
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -200,15 +200,14 @@ class CustomField(models.Model):
|
|||||||
# Select
|
# Select
|
||||||
elif self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
elif self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||||
choices = [(cfc.pk, cfc.value) for cfc in self.choices.all()]
|
choices = [(cfc.pk, cfc.value) for cfc in self.choices.all()]
|
||||||
|
default_choice = self.choices.filter(value=self.default).first()
|
||||||
|
|
||||||
if not required:
|
if not required or default_choice is None:
|
||||||
choices = add_blank_choice(choices)
|
choices = add_blank_choice(choices)
|
||||||
|
|
||||||
# Set the initial value to the PK of the default choice, if any
|
# Set the initial value to the PK of the default choice, if any
|
||||||
if set_initial:
|
if set_initial and default_choice:
|
||||||
default_choice = self.choices.filter(value=self.default).first()
|
initial = default_choice.pk
|
||||||
if default_choice:
|
|
||||||
initial = default_choice.pk
|
|
||||||
|
|
||||||
field_class = CSVChoiceField if for_csv_import else forms.ChoiceField
|
field_class = CSVChoiceField if for_csv_import else forms.ChoiceField
|
||||||
field = field_class(
|
field = field_class(
|
||||||
|
Loading…
Reference in New Issue
Block a user