Class Input


@Marshalled(typeName="input") public class Input extends HtmlElementVoid<Input>
DTO for an HTML <input> element.

The input element represents a form control that allows users to input data. It is a void element that can take many different forms depending on the type attribute, including text fields, checkboxes, radio buttons, file uploads, and more. The input element is one of the most versatile and commonly used form controls in HTML.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Text input field Input input1 = input("text") .name("username") .placeholder("Enter your username") .required(true); // Email input with validation Input input2 = input("email") .name("email") .placeholder("your@email.com") .autocomplete("email"); // File upload input Input input3 = input("file") .name("avatar") .accept("image/*") .multiple(true); // Checkbox input Input input4 = input("checkbox") .name("subscribe") .value("yes") .checked(true); // Password input with pattern Input input5 = input("password") .name("password") .pattern(".{8,}") .title("Password must be at least 8 characters");

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

  • Method Details

    • accept

      public Input accept(String value)
      accept attribute.

      Specifies which file types the file input should accept. Used with type="file".

      Examples:

      • "image/*" - Accept all image files
      • ".pdf,.doc,.docx" - Accept specific file extensions
      • "image/png,image/jpeg" - Accept specific MIME types
      Parameters:
      value - File type restrictions for file uploads. Can be null to unset the attribute.
      Returns:
      This object.
    • alt

      public Input alt(String value)
      alt attribute.

      Alternative text for image submit buttons. Used with type="image" to provide accessible text when the image cannot be displayed.

      Parameters:
      value - Alternative text for image submit buttons. Can be null to unset the attribute.
      Returns:
      This object.
    • autocomplete

      public Input autocomplete(String value)
      autocomplete attribute.

      Controls whether the browser can automatically complete the input field.

      Common values:

      • "on" - Allow autocomplete (default)
      • "off" - Disable autocomplete
      • "name" - Full name
      • "email" - Email address
      • "username" - Username or login
      • "current-password" - Current password
      • "new-password" - New password
      • "tel" - Telephone number
      • "url" - URL
      • "address-line1" - Street address
      • "country" - Country name
      • "postal-code" - Postal code
      Parameters:
      value - Autocomplete hint for the input field. Can be null to unset the attribute.
      Returns:
      This object.
    • autofocus

      public Input autofocus(Object value)
      autofocus attribute.

      Automatically focuses the form control when the page loads. Only one element per page should have this attribute.

      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • checked

      public Input checked(Object value)
      checked attribute.

      Whether the command or control is checked.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "checked"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • dirname

      public Input dirname(String value)
      dirname attribute.

      Specifies the name of a hidden form field that will be submitted along with the input value, containing the text direction (ltr or rtl) of the input content.

      This is useful for forms that need to preserve text direction information when submitted. The hidden field will contain either "ltr" or "rtl" based on the input's direction.

      Parameters:
      value - The name of the hidden field for directionality information. Can be null to unset the attribute.
      Returns:
      This object.
    • disabled

      public Input disabled(Object value)
      disabled attribute.

      Whether the form control is disabled.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "disabled"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • form

      public Input form(String value)
      form attribute.

      Associates the input with a form element by specifying the form's ID. This allows the input to be placed outside the form element while still being part of the form.

      The value should match the ID of a form element in the same document.

      Parameters:
      value - The ID of the form element to associate with this input. Can be null to unset the attribute.
      Returns:
      This object.
    • formaction

      public Input formaction(String value)
      formaction attribute.

      URL to use for form submission.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • formenctype

      public Input formenctype(String value)
      formenctype attribute.

      Form data set encoding type to use for form submission.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • formmethod

      public Input formmethod(String value)
      formmethod attribute.

      HTTP method to use for form submission.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • formnovalidate

      public Input formnovalidate(String value)
      formnovalidate attribute.

      Bypass form control validation for form submission.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • formtarget

      public Input formtarget(String value)
      formtarget attribute.

      Browsing context for form submission.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • height

      public Input height(Object value)
      height attribute.

      Vertical dimension.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • inputmode

      public Input inputmode(String value)
      inputmode attribute.

      Provides a hint to browsers about the type of virtual keyboard to display on mobile devices.

      Possible values:

      • "none" - No virtual keyboard
      • "text" - Standard text keyboard (default)
      • "tel" - Numeric keypad for telephone numbers
      • "url" - Keyboard optimized for URLs
      • "email" - Keyboard optimized for email addresses
      • "numeric" - Numeric keypad
      • "decimal" - Numeric keypad with decimal point
      • "search" - Keyboard optimized for search
      Parameters:
      value - The input modality hint for mobile keyboards. Can be null to unset the attribute.
      Returns:
      This object.
    • list

      public Input list(String value)
      list attribute.

      References a <datalist> element that provides predefined options for the input field. Creates a dropdown with autocomplete suggestions.

      Parameters:
      value - The ID of a datalist element (without the # prefix). Can be null to unset the attribute.
      Returns:
      This object.
    • max

      public Input max(Object value)
      max attribute.

      Maximum value.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • maxlength

      public Input maxlength(Object value)
      maxlength attribute. Maximum length of value.
      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute. Typically a Number or String.
      Returns:
      This object.
    • min

      public Input min(Object value)
      min attribute.

      Minimum value.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • minlength

      public Input minlength(Object value)
      minlength attribute.

      Minimum length of value.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • multiple

      public Input multiple(Object value)
      multiple attribute.

      Whether to allow multiple values.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "multiple"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • name

      public Input name(String value)
      name attribute.

      Name of form control to use for form submission and in the form.elements API.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • pattern

      public Input pattern(String value)
      pattern attribute.

      Specifies a regular expression that the input's value must match for the form to be valid. Works with the title attribute to provide user feedback.

      Parameters:
      value - A regular expression pattern (e.g., "[0-9]{3}-[0-9]{3}-[0-9]{4}" for phone numbers). Can be null to unset the attribute.
      Returns:
      This object.
    • placeholder

      public Input placeholder(String value)
      placeholder attribute.

      Provides a hint to the user about what to enter in the input field. The placeholder text appears when the field is empty and disappears when the user starts typing.

      Parameters:
      value - Hint text to display in the empty input field. Can be null to unset the attribute.
      Returns:
      This object.
    • readonly

      public Input readonly(boolean value)
      readonly attribute.

      Whether to allow the value to be edited by the user.

      Parameters:
      value - If true, adds readonly="readonly". Can be null to unset the attribute.
      Returns:
      This object.
    • readonly

      public Input readonly(Object value)
      readonly attribute.

      Makes the input field read-only, preventing user modification while still allowing the value to be submitted with the form.

      Parameters:
      value - If true, makes the input read-only. Can be null to unset the attribute.
      Returns:
      This object.
    • required

      public Input required(Object value)
      required attribute.

      Indicates that the input field must be filled out before the form can be submitted. Browsers will show validation messages for empty required fields.

      Parameters:
      value - If true, makes the input required for form submission. Can be null to unset the attribute.
      Returns:
      This object.
    • size

      public Input size(Object value)
      size attribute.

      Size of the control.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • src

      public Input src(Object value)
      src attribute.

      Address of the resource.

      Parameters:
      value - The new value for this attribute. Typically a URL or String. Can be null to unset the attribute.
      Returns:
      This object.
    • step

      public Input step(String value)
      step attribute.

      Granularity to be matched by the form control's value.

      Parameters:
      value - The new value for this attribute. Can be null to unset the attribute.
      Returns:
      This object.
    • type

      public Input type(String value)
      type attribute.

      Specifies the type of form control to display.

      Common values:

      • "text" - Single-line text input (default)
      • "password" - Password input (characters are masked)
      • "email" - Email address input with validation
      • "number" - Numeric input with spinner controls
      • "tel" - Telephone number input
      • "url" - URL input with validation
      • "search" - Search input field
      • "date" - Date picker
      • "time" - Time picker
      • "datetime-local" - Date and time picker
      • "checkbox" - Checkbox input
      • "radio" - Radio button input
      • "file" - File upload input
      • "submit" - Submit button
      • "button" - Generic button
      • "reset" - Reset form button
      • "hidden" - Hidden input field
      Parameters:
      value - The input type for the form control. Can be null to unset the attribute.
      Returns:
      This object.
    • value

      public Input value(Object value)
      value attribute.

      Value of the form control.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.
    • width

      public Input width(Object value)
      width attribute.

      Horizontal dimension.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.