Class NumberInput<T extends NumberInput<T>>


public class NumberInput<T extends NumberInput<T>> extends Input<T>
Represents an HTML5 <input type="number"> element for entering numeric values.

The NumberInput provides a text field optimized for numeric entry with optional spinner controls. It supports minimum, maximum, and step constraints for value validation.

Usage Example:


 NumberInput quantity = new NumberInput("quantity", "1");
 quantity.setMin(1);
 quantity.setMax(100);
 quantity.setStep(1);
 form.addElement(quantity);
 
Since:
HTML5
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • NumberInput

      public NumberInput()
      Creates a new NumberInput with no name or initial value.
    • NumberInput

      public NumberInput(String name)
      Creates a new NumberInput with the specified name.
      Parameters:
      name - The name attribute for the input element, used for form submission.
    • NumberInput

      public NumberInput(String name, String value)
      Creates a new NumberInput with the specified name and initial value.
      Parameters:
      name - The name attribute for the input element, used for form submission.
      value - The initial numeric value as a string.
  • Method Details

    • setMax

      public T setMax(int max)
      Sets the maximum allowed value for this number input.
      Parameters:
      max - The maximum integer value.
      Returns:
      this element for method chaining
    • setMax

      public T setMax(float max)
      Sets the maximum allowed value for this number input.
      Parameters:
      max - The maximum floating-point value.
      Returns:
      this element for method chaining
    • setMin

      public T setMin(int min)
      Sets the minimum allowed value for this number input.
      Parameters:
      min - The minimum integer value.
      Returns:
      this element for method chaining
    • setMin

      public T setMin(float min)
      Sets the minimum allowed value for this number input.
      Parameters:
      min - The minimum floating-point value.
      Returns:
      this element for method chaining
    • setStep

      public T setStep(int step)
      Sets the step interval for valid values.
      Parameters:
      step - The step interval as an integer.
      Returns:
      this element for method chaining
    • setStep

      public T setStep(float step)
      Sets the step interval for valid values.
      Parameters:
      step - The step interval as a floating-point value.
      Returns:
      this element for method chaining
    • setValue

      public void setValue(int value)
      Sets the current value of the number input.
      Parameters:
      value - The integer value to set.
    • setValue

      public void setValue(float value)
      Sets the current value of the number input.
      Parameters:
      value - The floating-point value to set.
    • setIgnoreValueNonchanges

      public final T setIgnoreValueNonchanges(boolean ignoreValueNonchanges)
      Sets whether to ignore input completion events when the value hasn't changed.

      When true (the default), InputCompleteEvent is only sent when the value actually changed during the focus session. When false, the event is sent on every blur regardless of whether the value changed.

      Parameters:
      ignoreValueNonchanges - true to suppress events when value unchanged, false to fire events on every blur.
      Returns:
      this element for method chaining
    • setText

      public final void setText(String text)
      Sets the text content of the input.
      Overrides:
      setText in class Element<T extends com.oorian.html.elements.BaseTextInput<T>>
      Parameters:
      text - The text to set as the input value.
    • selectText

      public final void selectText()
      Programmatically selects all text in the input field.

      Sends a command to the client to select the text content.

    • setSelectTextOnFocus

      public final void setSelectTextOnFocus()
      Configures the input to automatically select all text when clicked.
    • focusAndSelect

      public final void focusAndSelect()
      Sets focus to the input and selects all text.

      Combines focus and text selection into a single operation.

    • focusAndSetValue

      public final void focusAndSetValue(String value)
      Sets focus to the input and sets its value.

      Combines focus and value assignment into a single operation.

      Parameters:
      value - The value to set.
    • getText

      public final String getText()
      Returns the text content of the input.
      Returns:
      The current text value, or an empty string if no text.
    • getCleanText

      public final String getCleanText()
      Returns the trimmed text content of the input.
      Returns:
      The current text value with leading and trailing whitespace removed.
    • hasText

      public final boolean hasText()
      Checks whether the input contains non-empty text.
      Returns:
      true if the input contains non-whitespace text, false otherwise.
    • inputComplete

      public final void inputComplete()
      Called when input is completed in the text field.

      Dispatches an InputCompleteEvent and calls the BaseTextInput.onInputComplete() hook.

    • setTabOnKeyPressed

      public final T setTabOnKeyPressed(String keycode)
      Sets a key that will trigger tab behavior when pressed.
      Parameters:
      keycode - The key code as a string.
      Returns:
      this element for method chaining
    • setTabOnKeyPressed

      public final T setTabOnKeyPressed(int keycode)
      Sets a key that will trigger tab behavior when pressed.
      Parameters:
      keycode - The key code as an integer.
      Returns:
      this element for method chaining
    • setChangeOnEnter

      public final T setChangeOnEnter()
      Enables input completion on Enter key press.
      Returns:
      this element for method chaining
    • onInputComplete

      protected void onInputComplete()
      Hook method called when input is completed.

      Override this method to handle input completion events.