Class Form

java.lang.Object
io.mindspice.simplypages.core.HtmlTag
io.mindspice.simplypages.components.forms.Form
All Implemented Interfaces:
Component

public class Form extends HtmlTag
HTML form wrapper with fluent helpers for method, enctype, and HTMX attributes.

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.

  • Constructor Details

    • Form

      public Form()
      Creates a form with base class form.
  • Method Details

    • create

      public static Form create()
      Creates a new form.
      Returns:
      new form
    • withAction

      public Form withAction(String action)
      Sets an application-controlled or separately form-destination-validated action URL. Encoding does not validate schemes, authorize submission, or enforce CSRF.
      Parameters:
      action - action URL
      Returns:
      this form
    • withMethod

      public Form withMethod(Form.Method method)
      Sets logical method.

      For PUT/DELETE/PATCH, emits HTML method="POST" and appends a hidden _method override field.

      Parameters:
      method - logical method
      Returns:
      this form
    • withId

      public Form withId(String id)
      Sets id attribute.
      Overrides:
      withId in class HtmlTag
      Parameters:
      id - element id
      Returns:
      this form
    • withHxPost

      public Form withHxPost(String url)
      Sets hx-post to an application-controlled or separately endpoint-validated URL. Encoding does not enforce destination policy, authorization, or CSRF.
      Parameters:
      url - endpoint URL
      Returns:
      this form
    • withHxGet

      public Form withHxGet(String url)
      Sets hx-get to an application-controlled or separately endpoint-validated URL. Encoding does not enforce destination policy or authorization.
      Parameters:
      url - endpoint URL
      Returns:
      this form
    • withHxPut

      public Form withHxPut(String url)
      Sets hx-put to an application-controlled or separately endpoint-validated URL. Encoding does not enforce destination policy, authorization, or CSRF.
      Parameters:
      url - endpoint URL
      Returns:
      this form
    • withHxDelete

      public Form withHxDelete(String url)
      Sets hx-delete to an application-controlled or separately endpoint-validated URL. Encoding does not enforce destination policy, authorization, or CSRF.
      Parameters:
      url - endpoint URL
      Returns:
      this form
    • withHxTarget

      public Form withHxTarget(String target)
      Sets hx-target.
      Parameters:
      target - target selector
      Returns:
      this form
    • withHxSwap

      public Form withHxSwap(String swap)
      Sets hx-swap.
      Parameters:
      swap - swap strategy
      Returns:
      this form
    • withHxTrigger

      public Form withHxTrigger(String trigger)
      Sets hx-trigger.
      Parameters:
      trigger - trigger definition
      Returns:
      this form
    • withHxScrollTargetTop

      public Form withHxScrollTargetTop()
      Tags this HTMX request to scroll the swapped target fragment to top after settle.
      Returns:
      this form
    • withEnctype

      public Form withEnctype(String enctype)
      Sets enctype.
      Parameters:
      enctype - encoding type
      Returns:
      this form
    • multipart

      public Form multipart()
      Convenience for multipart form encoding.
      Returns:
      this form
    • noValidate

      public Form noValidate()
      Sets novalidate.
      Returns:
      this form
    • withCsrfHeaderName

      public Form withCsrfHeaderName(String name)
      Sets the CSRF header name used by withHxPostCsrf(String, String).
      Parameters:
      name - header name
      Returns:
      this form
    • withCsrfToken

      public Form withCsrfToken(String token)
      Appends hidden _csrf input.
      Parameters:
      token - CSRF token value
      Returns:
      this form
    • withHxPostCsrf

      public Form withHxPostCsrf(String url, String csrfToken)
      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 to
      csrfToken - the CSRF token value
      Returns:
      this form
    • withClass

      public Form withClass(String className)
      Replaces class attribute with form <className>.
      Overrides:
      withClass in class HtmlTag
      Parameters:
      className - additional classes
      Returns:
      this form
    • withChild

      public Form withChild(Component component)
      Appends child component.
      Overrides:
      withChild in class HtmlTag
      Parameters:
      component - child component
      Returns:
      this form
    • addField

      public Form addField(String label, Component input)
      Appends a field wrapper containing optional label and input component.

      For TextInput, TextArea, Select, Checkbox, and Button, 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 through aria-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/empty
      input - input component
      Returns:
      this form