Skip to content

Allow ChoiceVar() to have optional setting #8228

@candlerb

Description

@candlerb

NetBox version

v3.1.4

Feature type

Change to existing functionality

Proposed functionality

When you set required=False on a ChoiceVar, have no choice selected by default, and allow the user not to select anything.

Currently, if you have e.g.

cable_color = ChoiceVar(choices=ColorChoices.CHOICES, required=False, label="Cable Color")

then there is an arbitrary color chosen by default, and the user is required to select one.

Use case

For using built-in choices like CableTypeChoices.CHOICES or ColorChoices.CHOICES where no choice is a valid selection.

Workaround:

NO_CHOICE = (
        ('', '---------'),
)

cable_color = ChoiceVar(choices=NO_CHOICE+ColorChoices.CHOICES, required=False, label="Cable Color")

(Note however that required=False is still required)

Database changes

None

External dependencies

None

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions