mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 03:56:53 -06:00
Fixes #8228: Optional ChoiceVar fields should not force a selection
This commit is contained in:
parent
574c2e2770
commit
b1d1f3c6b2
@ -12,6 +12,7 @@
|
|||||||
* [#8213](https://github.com/netbox-community/netbox/issues/8213) - Fix ValueError exception under prefix IP addresses view
|
* [#8213](https://github.com/netbox-community/netbox/issues/8213) - Fix ValueError exception under prefix IP addresses view
|
||||||
* [#8224](https://github.com/netbox-community/netbox/issues/8224) - Fix KeyError exception when creating FHRP group with IP address and protocol "other"
|
* [#8224](https://github.com/netbox-community/netbox/issues/8224) - Fix KeyError exception when creating FHRP group with IP address and protocol "other"
|
||||||
* [#8226](https://github.com/netbox-community/netbox/issues/8226) - Honor return URL after populating a device bay
|
* [#8226](https://github.com/netbox-community/netbox/issues/8226) - Honor return URL after populating a device bay
|
||||||
|
* [#8228](https://github.com/netbox-community/netbox/issues/8228) - Optional ChoiceVar fields should not force a selection
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from extras.models import JobResult
|
|||||||
from ipam.formfields import IPAddressFormField, IPNetworkFormField
|
from ipam.formfields import IPAddressFormField, IPNetworkFormField
|
||||||
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
|
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
|
||||||
from utilities.exceptions import AbortTransaction
|
from utilities.exceptions import AbortTransaction
|
||||||
from utilities.forms import DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
from utilities.forms import add_blank_choice, DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
||||||
from .context_managers import change_logging
|
from .context_managers import change_logging
|
||||||
from .forms import ScriptForm
|
from .forms import ScriptForm
|
||||||
|
|
||||||
@ -164,16 +164,22 @@ class ChoiceVar(ScriptVariable):
|
|||||||
def __init__(self, choices, *args, **kwargs):
|
def __init__(self, choices, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Set field choices
|
# Set field choices. Add a blank choice if this field is not required.
|
||||||
self.field_attrs['choices'] = choices
|
self.field_attrs['choices'] = choices if kwargs.get('required') else add_blank_choice(choices)
|
||||||
|
|
||||||
|
|
||||||
class MultiChoiceVar(ChoiceVar):
|
class MultiChoiceVar(ScriptVariable):
|
||||||
"""
|
"""
|
||||||
Like ChoiceVar, but allows for the selection of multiple choices.
|
Like ChoiceVar, but allows for the selection of multiple choices.
|
||||||
"""
|
"""
|
||||||
form_field = forms.MultipleChoiceField
|
form_field = forms.MultipleChoiceField
|
||||||
|
|
||||||
|
def __init__(self, choices, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Set field choices
|
||||||
|
self.field_attrs['choices'] = choices
|
||||||
|
|
||||||
|
|
||||||
class ObjectVar(ScriptVariable):
|
class ObjectVar(ScriptVariable):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user