validation

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package validation enables your handler to return validation errors. Each validation error is displayed by the corresponding input.Input field: - the input switches to style.StyleInvalid - the error message is displayed below the field

Handler code:

_ = validation.Retarget(r.Context(), validation.D{
	FormID: "profile",
	Errors: map[string]string{"Email": "Email is mandatory"},
}, w, http.StatusUnprocessableEntity)

Template code:

@form.C(form.D{ID:"profile"}) {
	@input.C(input.D{Name: "Email", Type: input.TypeEmail})
}

templ: version: v0.2.793

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(def D) templ.Component

func Retarget

func Retarget(ctx context.Context, def D, w http.ResponseWriter, statusCode int) error

Retarget retargets the response to display validation errors in a form.

Types

type D

type D struct {
	// FormID is the ID of the form to target.
	FormID string
	// Errors is the list of errors to display.
	Errors map[string]string
}

D is the validation retarget response.

Directories

Path Synopsis
templ: version: v0.2.793
templ: version: v0.2.793

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL