Components Forms

Field

Keep a label, its input, help text, and a validation message together.

Live previewGo + HTML

Use 3–24 letters, digits, or dashes.

Spaces are not allowed in this handle.

Usage

Supply Error after validating the submitted value on the server. The input receives aria-invalid and references the message. Omit Error on a valid response.

Register field with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "field", mono.Props{
	"Error":    "Spaces are not allowed in this handle.",
	"Hint":     "Use 3–24 letters, digits, or dashes.",
	"Label":    "Account handle",
	"Name":     "handle",
	"Required": true,
	"Value":    "studio proof",
})
Rendered HTML
Rendered HTML
<div id="demo-field" data-mono="field" class="mu-stack">
  <label class="mu-label" for="demo-field-value">Account handle</label>
  <input id="demo-field-value" class="mu-field" type="text" name="handle" value="studio proof" required aria-invalid="true" aria-describedby="demo-field-hint demo-field-error">
  <p id="demo-field-hint" class="mu-small mu-muted">Use 3–24 letters, digits, or dashes.</p>
  <strong id="demo-field-error" class="mu-small">Spaces are not allowed in this handle.</strong>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="field" class="mu-stack">
  <label class="mu-label" for="{{.ID}}-value">{{.Label}}</label>
  <input id="{{.ID}}-value" class="mu-field" type="{{or .Type "text"}}" name="{{or .Name .ID}}" value="{{.Value}}" {{if .Required}}required{{end}} {{if .Error}}aria-invalid="true"{{end}} {{if or .Hint .Error}}aria-describedby="{{if .Hint}}{{.ID}}-hint {{end}}{{if .Error}}{{.ID}}-error{{end}}"{{end}}>
  {{if .Hint}}<p id="{{.ID}}-hint" class="mu-small mu-muted">{{.Hint}}</p>{{end}}
  {{if .Error}}<strong id="{{.ID}}-error" class="mu-small">{{.Error}}</strong>{{end}}
</div>
Component CSS
Component CSS
[data-mono="field"] [aria-invalid="true"] { border-style: dashed; border-width: 2px; }
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS Component CSS

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./field.css">

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components field
Example properties (JSON)
example.json
{
  "Error": "Spaces are not allowed in this handle.",
  "Hint": "Use 3–24 letters, digits, or dashes.",
  "Label": "Account handle",
  "Name": "handle",
  "Required": true,
  "Value": "studio proof"
}