forms

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package forms implements browser-owned HTML form state and serialization.

Index

Constants

View Source
const (
	URLEncoded          = "application/x-www-form-urlencoded"
	MaxFormEntries      = 1000
	MaxEncodedFormBytes = 1 << 20
)

Variables

View Source
var ErrFormDataTooLarge = errors.New("form data exceeds safety limit")

Functions

func ActivateCheckable

func ActivateCheckable(document *dom.Document, nodeID dom.NodeID) (bool, bool)

ActivateCheckable applies the default activation behavior and returns the resulting checked state when it changed.

func CurrentChecked

func CurrentChecked(node *dom.Node) bool

CurrentChecked returns checked state, preferring live state over the default attribute.

func CurrentValue

func CurrentValue(node *dom.Node) string

CurrentValue returns a control's live value without overwriting its default.

func Disabled

func Disabled(node *dom.Node) bool

Disabled reports whether the control itself or an ancestor fieldset is disabled.

func EditableTextControlType

func EditableTextControlType(node *dom.Node) (string, bool)

EditableTextControlType returns the normalized type of an editable text control. Unknown input types use the HTML text fallback.

func EncodeURLEncoded

func EncodeURLEncoded(entries []Entry) string

EncodeURLEncoded serializes entries as UTF-8 application/x-www-form-urlencoded.

func EncodeURLEncodedLimited

func EncodeURLEncodedLimited(entries []Entry) (string, error)

EncodeURLEncodedLimited serializes entries while enforcing release safety limits.

func FirstInvalidControl

func FirstInvalidControl(document *dom.Document, form *dom.Node) (*dom.Node, bool)

FirstInvalidControl returns the first invalid descendant in DOM order.

func FocusableControls

func FocusableControls(document *dom.Document) []dom.NodeID

FocusableControls returns enabled form controls in DOM order.

func FormOwner

func FormOwner(document *dom.Document, control *dom.Node) *dom.Node

FormOwner resolves an explicit form=id association before ancestor lookup.

func IsEditableTextControl

func IsEditableTextControl(node *dom.Node) bool

IsEditableTextControl reports whether users can edit a control as text.

func IsSubmitButton

func IsSubmitButton(node *dom.Node) bool

IsSubmitButton reports whether a button performs form submission.

func LabeledControl

func LabeledControl(document *dom.Document, node *dom.Node) *dom.Node

LabeledControl resolves a label target using for=id or its first descendant control.

func NextEnabledValue

func NextEnabledValue(options []Option, selected int) (string, bool)

NextEnabledValue returns the next enabled option, wrapping at the end.

func NextFocusable

func NextFocusable(document *dom.Document, current dom.NodeID, reverse bool) dom.NodeID

NextFocusable returns the next or previous control, wrapping at the ends.

func ReadOnly

func ReadOnly(node *dom.Node) bool

ReadOnly reports whether an editable text control has the readonly attribute.

func Reset

func Reset(form *dom.Node) bool

Reset restores descendants of a form to attribute-backed defaults.

func SelectedIndex

func SelectedIndex(selectNode *dom.Node, options []Option) int

SelectedIndex resolves current value, selected content attribute, then the first option in that order. It returns -1 for an empty select.

func SetCurrentValue

func SetCurrentValue(node *dom.Node, value string) bool

SetCurrentValue changes browser-owned live state and marks it dirty.

func SetSelectedValue

func SetSelectedValue(document *dom.Document, nodeID dom.NodeID, value string) bool

SetSelectedValue updates a select to an enabled option value.

func WillValidate

func WillValidate(node *dom.Node) bool

WillValidate reports whether a control participates in constraint validation.

Types

type Checkable

type Checkable struct {
	Kind    string
	Checked bool
}

Checkable describes a checkbox or radio input's current state.

func CheckableState

func CheckableState(node *dom.Node) (Checkable, bool)

CheckableState resolves a checkbox or radio input.

type Entry

type Entry struct {
	Name  string
	Value string
}

Entry is one successful control name/value pair.

func CollectEntries

func CollectEntries(document *dom.Document, form, submitter *dom.Node) []Entry

CollectEntries builds the successful-control entry list in document order.

type Option

type Option struct {
	NodeID   dom.NodeID
	Value    string
	Label    string
	Disabled bool
}

Option is one flattened option in DOM order.

func SelectOptions

func SelectOptions(selectNode *dom.Node) []Option

SelectOptions returns option descendants in DOM order.

type SubmissionConfig

type SubmissionConfig struct {
	Form       *dom.Node
	Submitter  *dom.Node
	Action     string
	Method     string
	Enctype    string
	Target     string
	NoValidate bool
}

SubmissionConfig is the form configuration after submitter overrides.

func ResolveFormSubmission

func ResolveFormSubmission(document *dom.Document, form, submitter *dom.Node) (SubmissionConfig, bool)

ResolveFormSubmission resolves a form with an optional submitter.

func ResolveSubmission

func ResolveSubmission(document *dom.Document, submitter *dom.Node) (SubmissionConfig, bool)

ResolveSubmission applies defaults and submitter-specific overrides.

type Validity

type Validity struct {
	ValueMissing    bool
	TooShort        bool
	TooLong         bool
	RangeUnderflow  bool
	RangeOverflow   bool
	StepMismatch    bool
	TypeMismatch    bool
	PatternMismatch bool
}

Validity is the supported subset of HTML constraint validation state.

func ValidateControl

func ValidateControl(document *dom.Document, node *dom.Node) Validity

ValidateControl evaluates supported constraints against browser-owned live state.

func (Validity) Valid

func (validity Validity) Valid() bool

Valid reports whether none of the supported constraints failed.

Jump to

Keyboard shortcuts

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