Class Form
- All Implemented Interfaces:
Component
Mutable and not thread-safe. Configure per request; avoid reusing one instance across threads. For reuse, stop mutating shared instances and render stable structures with per-request context data.
Security boundary: this component can attach CSRF tokens but does not generate or validate them. Token issuance/validation remains an application responsibility.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSupported logical HTTP methods for form submission. -
Field Summary
Fields inherited from class HtmlTag
attributes, children, id, innerText, innerTextSlot, selfClosing, tagName, trustedHtml -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends a field wrapper containing optional label and input component.static Formcreate()Creates a new form.Convenience for multipart form encoding.Setsnovalidate.withAction(String action) Sets an application-controlled or separately form-destination-validated action URL.Appends child component.Replaces class attribute withform <className>.withCsrfHeaderName(String name) Sets the CSRF header name used bywithHxPostCsrf(String, String).withCsrfToken(String token) Appends hidden_csrfinput.withEnctype(String enctype) Setsenctype.withHxDelete(String url) Setshx-deleteto an application-controlled or separately endpoint-validated URL.Setshx-getto an application-controlled or separately endpoint-validated URL.withHxPost(String url) Setshx-postto an application-controlled or separately endpoint-validated URL.withHxPostCsrf(String url, String csrfToken) Attaches a CSRF header to HTMX POST using an application-controlled or separately endpoint-validated URL.Setshx-putto an application-controlled or separately endpoint-validated URL.Tags this HTMX request to scroll the swapped target fragment to top after settle.withHxSwap(String swap) Setshx-swap.withHxTarget(String target) Setshx-target.withHxTrigger(String trigger) Setshx-trigger.Sets id attribute.withMethod(Form.Method method) Sets logical method.Methods inherited from class HtmlTag
addClass, addStyle, addTrustedStyle, getChildrenStream, getId, hxDelete, hxGet, hxInclude, hxPatch, hxPost, hxPushUrl, hxPut, hxScrollTargetTop, hxSwap, hxTarget, hxTrigger, render, withAttribute, withInnerText, withInnerText, withMaxWidth, withMinWidth, withUnsafeHtml, withWidth
-
Constructor Details
-
Form
public Form()Creates a form with base classform.
-
-
Method Details
-
create
-
withAction
-
withMethod
Sets logical method.For
PUT/DELETE/PATCH, emits HTMLmethod="POST"and appends a hidden_methodoverride field.- Parameters:
method- logical method- Returns:
- this form
-
withId
-
withHxPost
-
withHxGet
-
withHxPut
-
withHxDelete
-
withHxTarget
-
withHxSwap
-
withHxTrigger
-
withHxScrollTargetTop
Tags this HTMX request to scroll the swapped target fragment to top after settle.- Returns:
- this form
-
withEnctype
-
multipart
-
noValidate
-
withCsrfHeaderName
Sets the CSRF header name used bywithHxPostCsrf(String, String).- Parameters:
name- header name- Returns:
- this form
-
withCsrfToken
-
withHxPostCsrf
Attaches a CSRF header to HTMX POST using an application-controlled or separately endpoint-validated URL. This does not validate destinations, issue/verify tokens, or authorize requests; token and endpoint enforcement belong to the application.- Parameters:
url- the URL to POST tocsrfToken- the CSRF token value- Returns:
- this form
-
withClass
-
withChild
-
addField
Appends a field wrapper containing optional label and input component.For
TextInput,TextArea,Select,Checkbox, andButton, a nonempty label targets the control's existing ID, or a unique ID assigned during this call. Checkbox IDs target its internal input, not its wrapper. Configure control IDs before adding fields; changing an ID later does not update the assembled field label.For
RadioGroup, the caption names the group througharia-labelledby; individual option labels are unchanged. Other components receive only a visible caption. Applications must compose their own labels or accessible names for arbitrary/custom and multi-control components; this method does not inspect their markup or infer a target.- Parameters:
label- label text; omitted when null/emptyinput- input component- Returns:
- this form
-