Skip to content
Gx
GitHub

GX2017: form control has no label

An input, a select or a textarea has no label that the file shows.

Cause

A form control needs a name that a screen reader can say. A placeholder is not a label: it goes away when the user types.

Gx reads one file. A control has a label when one of these is true:

  • It is inside a label element.
  • It has an id, and a label of the file has the same value in for.
  • It has aria-label, aria-labelledby or title.

Gx gives no finding for a control with a spread, and for an input with the type hidden, submit, button, reset or image.

Example

search/Box.gx
package search

<form action="/search">
  <input type="search" name="q" placeholder="Search">
  <button type="submit">Go</button>
</form>

gx check reports:

gx check
search/Box.gx:4:3: GX2017: the <input> has no label

Fix

  1. Put the control inside a label: <label>Search <input type="search" name="q"></label>.
  2. Or give it an id and write <label for="..."> with that id.
  3. For a control with no visible label, write aria-label="Search".