Skip to content

Commit f5b783a

Browse files
committed
allow_blank in ChoiceField. Refs #2239.
1 parent 54a18a4 commit f5b783a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/api-guide/fields.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ Used by `ModelSerializer` to automatically generate fields if the corresponding
310310
**Signature:** `ChoiceField(choices)`
311311

312312
- `choices` - A list of valid values, or a list of `(key, display_name)` tuples.
313+
- `allow_blank` - If set to `True` then the empty string should be considered a valid value. If set to `False` then the empty string is considered invalid and will raise a validation error. Defaults to `False`.
314+
315+
Both the `allow_blank` and `allow_null` are valid options on `ChoiceField`, although it is highly recommended that you only use one and not both. `allow_blank` should be preferred for textual choices, and `allow_null` should be preferred for numeric or other non-textual choices.
313316

314317
## MultipleChoiceField
315318

@@ -318,6 +321,9 @@ A field that can accept a set of zero, one or many values, chosen from a limited
318321
**Signature:** `MultipleChoiceField(choices)`
319322

320323
- `choices` - A list of valid values, or a list of `(key, display_name)` tuples.
324+
- `allow_blank` - If set to `True` then the empty string should be considered a valid value. If set to `False` then the empty string is considered invalid and will raise a validation error. Defaults to `False`.
325+
326+
As with `ChoiceField`, both the `allow_blank` and `allow_null` options are valid, although it is highly recommended that you only use one and not both. `allow_blank` should be preferred for textual choices, and `allow_null` should be preferred for numeric or other non-textual choices.
321327

322328
---
323329

0 commit comments

Comments
 (0)