Error when setting default value for multiple selection custom field #5016

Closed
opened 2025-12-29 19:23:10 +01:00 by adam · 5 comments
Owner

Originally created by @saruter on GitHub (Jun 18, 2021).

NetBox version

v2.11.4

Python version

3.6

Steps to Reproduce

  1. Add custom field type "Multiple Selection"
  2. Add a default value for it, it is a string, for example "red" (with double quotes)
  3. Add Choices: red,blue,green
  4. Add Content-Type: Site
  5. Click Save
  6. Error at Default field: "Invalid default value "red": Invalid choice(s) (r, e, d). Available choices are: red, green, blue"

Expected Behavior

A default value is possible to set for a multiple select custom field.

Observed Behavior

Error Message at Default-Value-Field:
Invalid default value "red": Invalid choice(s) (r, e, d). Available choices are: red, green, blue

Originally created by @saruter on GitHub (Jun 18, 2021). ### NetBox version v2.11.4 ### Python version 3.6 ### Steps to Reproduce 1) Add custom field type "Multiple Selection" 2) Add a default value for it, it is a string, for example "red" (with double quotes) 3) Add Choices: red,blue,green 4) Add Content-Type: Site 5) Click Save 6) Error at Default field: "Invalid default value "red": Invalid choice(s) (r, e, d). Available choices are: red, green, blue" ### Expected Behavior A default value is possible to set for a multiple select custom field. ### Observed Behavior Error Message at Default-Value-Field: Invalid default value "red": Invalid choice(s) (r, e, d). Available choices are: red, green, blue
adam added the pending closurestatus: under review labels 2025-12-29 19:23:10 +01:00
adam closed this issue 2025-12-29 19:23:10 +01:00
Author
Owner

@drmsoffall commented on GitHub (Jun 19, 2021):

The multi-select field wants an array as a default value. Try setting it like this:

["red"]

The square brackets are needed, even if the default is only one value.

@drmsoffall commented on GitHub (Jun 19, 2021): The multi-select field wants an array as a default value. Try setting it like this: ``` ["red"] ``` The square brackets are needed, even if the default is only one value.
Author
Owner

@jeremystretch commented on GitHub (Jun 21, 2021):

This feels like a bug at first, but I think @drmsoffall's approach is correct. We're specifying the field's default value, which should be a raw JSON value. Since a multi-select custom field may have a default value containing multiple selections, the default value should be specified as a list.

@jeremystretch commented on GitHub (Jun 21, 2021): This feels like a bug at first, but I think @drmsoffall's approach is correct. We're specifying the field's default value, which should be a raw JSON value. Since a multi-select custom field may have a default value containing multiple selections, the default value should be specified as a list.
Author
Owner

@proudbro commented on GitHub (Jun 28, 2021):

I noticed that if we specify any single value in multiple selection custom field, then we will see it in this form:
t,e,s,t
That is, each letter is separated by a comma

If I add a second value to this field, for example test1, I will see both values in their normal form:
test, test1

@proudbro commented on GitHub (Jun 28, 2021): I noticed that if we specify any single value in multiple selection custom field, then we will see it in this form: `t,e,s,t` That is, each letter is separated by a comma If I add a second value to this field, for example `test1`, I will see both values in their normal form: `test, test1`
Author
Owner

@github-actions[bot] commented on GitHub (Aug 28, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 28, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Sep 27, 2021):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Sep 27, 2021): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5016