Reset User Input
Form clears automatically after successful submission — no extra attributes needed.
Submit a message and the input clears itself, ready for the next one. There's nothing special to wire: the server re-renders the form from fresh state after the action, so the field comes back empty while the submitted values are kept in the list.
A plain form plus a list of submitted messages. No reset attribute, no client JS.
{{define "content"}}
<article>
<h3>Reset User Input</h3>
<p><small>Form clears automatically after successful submission — no extra attributes needed.</small></p>
<form method="POST">
<fieldset role="group">
<input name="message" placeholder="Type a message..." aria-label="Message" required>
<button type="submit">Send</button>
</fieldset>
</form>
{{range .Messages}}
<p>{{.}}</p>
{{end}}
</article>
{{end}}
Submit appends the message; because the input isn't bound to retained state, the
re-render starts it empty.
type ResetInputController struct{}
func (c *ResetInputController) Submit(state ResetInputState, ctx *livetemplate.Context) (ResetInputState, error) {
msg := ctx.GetString("message")
if msg != "" {
state.Messages = append(state.Messages, msg)
}
return state, nil
}
func resetInputHandler() http.Handler {
tmpl := newLayoutTmpl("templates/layout.tmpl", "templates/forms/reset-input.tmpl")
return tmpl.Handle(&ResetInputController{}, livetemplate.AsState(&ResetInputState{
Title: "Reset User Input",
Category: "Forms & Editing",
}))
}
type ResetInputState struct {
Title string
Category string
Messages []string
}