Documentation
¶
Overview ¶
templ: version: v0.3.977
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(fn ValidateFunc) http.HandlerFunc
Handler returns an http.HandlerFunc for a single ValidateFunc. The component ID is passed as a query parameter "id".
Mount each validator at its own path:
r.Get("/validate/email", validator.Handler(emailValidator))
r.Get("/validate/phone", validator.Handler(phoneValidator))
The component references this path via the ValidateURL prop.
func Input ¶
func Input(props InputProps) templ.Component
Input renders a DaisyUI input with server-side validation via Datastar. On input change (debounced), it calls the backend validator and shows/hides a validation hint based on the result.
func SuccessHint ¶
SuccessHint renders a hint that is visible only when validation succeeds and the input has a non-empty value.
Types ¶
type InputProps ¶
type InputProps struct {
// ID uniquely identifies this validator instance. Required.
ID string
// Class adds additional CSS classes to the input element.
Class string
// Attributes adds arbitrary HTML attributes to the input element.
Attributes templ.Attributes
// Type is the HTML input type. Defaults to TypeText.
Type InputType
// Name is the form field name attribute.
Name string
// Placeholder is the input placeholder text.
Placeholder string
// Value is the initial input value.
Value string
// Validate is a built-in validation type (e.g. validator.Email).
// When set, ValidateURL is resolved automatically using BasePath.
Validate Validation
// ValidateURL is the endpoint path for server-side validation.
// The component appends "?id=<ID>" automatically.
// Overrides Validate if both are set.
ValidateURL string
// DebounceMs is the debounce delay in milliseconds. Defaults to 500.
DebounceMs int
// HintText is the error hint shown when validation fails.
// If empty, the backend error message is used.
HintText string
}
InputProps configures a validated input field.
type ValidateFunc ¶
ValidateFunc validates a string value and returns a Result.
type Validation ¶ added in v0.0.31
type Validation string
Validation identifies a built-in server-side validation type.
const ( // Email validates email format (regex-based). Email Validation = "email" // EmailMX validates email format and checks MX records. EmailMX Validation = "email-mx" // IBANValidation validates IBAN format and checksum. IBANValidation Validation = "iban" // SWIFTValidation validates SWIFT/BIC code format. SWIFTValidation Validation = "swift" )
func (Validation) Path ¶ added in v0.0.31
func (v Validation) Path() string
Path returns the handler path for a built-in validation type. Use with webx.Context.APIPath to build the full URL.