Sub topic 7
Making fields required
This chapter assumes you can read YAML and have already seen the issue form structure and element types from the previous chapters. Here you will control which fields a reporter must complete before GitHub accepts the issue.
Where required lives
Each form element can have a validations key. Inside it, required: true marks the field as mandatory. The key sits next to attributes, not inside it.
body:
- type: input
id: version
attributes:
label: Version
validations:
required: trueGitHub shows a red asterisk next to the label and disables submission until the field has a value.
Which elements accept validations
| Element | Where `required` goes | Effect |
|---|---|---|
| `input` | `validations.required` | Field must not be empty |
| `textarea` | `validations.required` | Field must not be empty |
| `dropdown` | `validations.required` | An option must be selected |
| `checkboxes` | `required` on each item in `options` | That box must be ticked |
| `markdown` | Not supported | Display only, nothing to fill in |
The checkboxes element is the exception. It has no validations block. You set required: true on individual options, so one form can mix mandatory and optional boxes.
A form with required and optional fields
name: Bug report
description: Report something that is not working
title: "[Bug]: "
labels: ["bug", "triage"]
body:
- type: markdown
attributes:
value: |
Fields marked with an asterisk are required.
- type: input
id: version
attributes:
label: Version
placeholder: "1.4.2"
validations:
required: true
- type: dropdown
id: os
attributes:
label: Operating system
options:
- Windows
- macOS
- Linux
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to reproduce
validations:
required: true
- type: textarea
id: logs
attributes:
label: Relevant log output
render: shell
- type: checkboxes
id: terms
attributes:
label: Before submitting
options:
- label: I searched existing issues for duplicates
required: true
- label: I am willing to test a fixIn this form, version, os, and steps must be filled in. The log field is optional. The first checkbox must be ticked, and the second is a free choice.
What happens on submit
Common errors
- Wrong indentation. If
validationsis indented underattributes, the form fails to validate. Align it withattributes. - Required on a markdown element. GitHub rejects
validationsonmarkdownbecause the element has no input. - Required on the checkboxes element. Put
required: trueon each option, not on the element. - Quoting problems.
required: "true"is a string, not a boolean. Write it without quotes. - Duplicate
idvalues. Everyidmust be unique within the form. Duplicates make the whole template invalid, and it will not appear in the chooser.
Limits of required fields
Required fields apply only to issue forms. Markdown issue templates and pull request templates are plain text. Nothing stops a contributor from deleting a checklist item or leaving a section empty.
Enforcement also happens in the web form only. Issues created through the API, GitHub CLI, or an edited URL are not checked against required. If you must guarantee content, pair the form with a workflow that labels or closes issues missing information.
Exercise
You want a feature request form where the "Problem" textarea is mandatory and a "Willing to help implement" checkbox is optional. Where do you place required: true for each?
Show answer
For the textarea, add a validations block aligned with attributes and set required: true inside it. For the checkbox, add no required key, or set it to false, on that option in the checkboxes element. Checkbox requirements go on each option, never in a validations block.