Documentation
¶
Overview ¶
Package forms implements browser-owned HTML form state and serialization.
Index ¶
- Constants
- Variables
- func ActivateCheckable(document *dom.Document, nodeID dom.NodeID) (bool, bool)
- func CurrentChecked(node *dom.Node) bool
- func CurrentValue(node *dom.Node) string
- func Disabled(node *dom.Node) bool
- func EditableTextControlType(node *dom.Node) (string, bool)
- func EncodeURLEncoded(entries []Entry) string
- func EncodeURLEncodedLimited(entries []Entry) (string, error)
- func FirstInvalidControl(document *dom.Document, form *dom.Node) (*dom.Node, bool)
- func FocusableControls(document *dom.Document) []dom.NodeID
- func FormOwner(document *dom.Document, control *dom.Node) *dom.Node
- func IsEditableTextControl(node *dom.Node) bool
- func IsSubmitButton(node *dom.Node) bool
- func LabeledControl(document *dom.Document, node *dom.Node) *dom.Node
- func NextEnabledValue(options []Option, selected int) (string, bool)
- func NextFocusable(document *dom.Document, current dom.NodeID, reverse bool) dom.NodeID
- func ReadOnly(node *dom.Node) bool
- func Reset(form *dom.Node) bool
- func SelectedIndex(selectNode *dom.Node, options []Option) int
- func SetCurrentValue(node *dom.Node, value string) bool
- func SetSelectedValue(document *dom.Document, nodeID dom.NodeID, value string) bool
- func WillValidate(node *dom.Node) bool
- type Checkable
- type Entry
- type Option
- type SubmissionConfig
- type Validity
Constants ¶
const ( URLEncoded = "application/x-www-form-urlencoded" MaxFormEntries = 1000 MaxEncodedFormBytes = 1 << 20 )
Variables ¶
var ErrFormDataTooLarge = errors.New("form data exceeds safety limit")
Functions ¶
func ActivateCheckable ¶
ActivateCheckable applies the default activation behavior and returns the resulting checked state when it changed.
func CurrentChecked ¶
CurrentChecked returns checked state, preferring live state over the default attribute.
func CurrentValue ¶
CurrentValue returns a control's live value without overwriting its default.
func EditableTextControlType ¶
EditableTextControlType returns the normalized type of an editable text control. Unknown input types use the HTML text fallback.
func EncodeURLEncoded ¶
EncodeURLEncoded serializes entries as UTF-8 application/x-www-form-urlencoded.
func EncodeURLEncodedLimited ¶
EncodeURLEncodedLimited serializes entries while enforcing release safety limits.
func FirstInvalidControl ¶
FirstInvalidControl returns the first invalid descendant in DOM order.
func FocusableControls ¶
FocusableControls returns enabled form controls in DOM order.
func IsEditableTextControl ¶
IsEditableTextControl reports whether users can edit a control as text.
func IsSubmitButton ¶
IsSubmitButton reports whether a button performs form submission.
func LabeledControl ¶
LabeledControl resolves a label target using for=id or its first descendant control.
func NextEnabledValue ¶
NextEnabledValue returns the next enabled option, wrapping at the end.
func NextFocusable ¶
NextFocusable returns the next or previous control, wrapping at the ends.
func SelectedIndex ¶
SelectedIndex resolves current value, selected content attribute, then the first option in that order. It returns -1 for an empty select.
func SetCurrentValue ¶
SetCurrentValue changes browser-owned live state and marks it dirty.
func SetSelectedValue ¶
SetSelectedValue updates a select to an enabled option value.
func WillValidate ¶
WillValidate reports whether a control participates in constraint validation.
Types ¶
type Option ¶
Option is one flattened option in DOM order.
func SelectOptions ¶
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 ¶
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 ¶
ValidateControl evaluates supported constraints against browser-owned live state.