Fields
WebforJ supports seven different types of field components, each with different behaviors and implementations that suit various needs. While each of these components have variations in their implementations, this article describes commonalities among all of the field classes.
This section describes common features of various field components in webforJ, and isn't itself a class that can be instantiated and used.
Shared field properties
Label
A field label is a descriptive text or title that is associated with the field. It provides a brief explanation or prompt to help users understand the purpose or expected input for that particular field. Field labels are not only important for usability but also play a crucial role in accessibility, as they enable screen readers and assistive technologies to provide accurate information and facilitate keyboard navigation.
Helper text
Each field can display helper text beneath the input using the setHelperText()
method. This helper text offers additional context or explanations about the available inputs, ensuring users have the necessary information to make informed selections.
Required
A field is required when the user must provide a value before submitting a form. This is mainly used in conjunction with setLabel(String)
to provide a visual indication to users that the field is required.
Field components contain built-in visual validation which notifies users if a required field is empty, or has had values removed.
Spellcheck
By calling the setSpellCheck(true)
method, you can enable the spellcheck feature for a field. This means that when a user enters text into the field, the browser or user agent may check the spelling of the entered text for errors.
Slots
Slots provide flexible options for improving the capability of field components. You can have icons, labels, loading spinners, clear/reset capability, avatar/profile pictures, and other beneficial components nested within a field to further clarify intended meaning to users.
Fields have two slots: the prefix
and suffix
slots. Use the setPrefixComponent()
and setSuffixComponent()
methods to insert various components before and after the displayed option within a field. Here's an example using the TextField
field:
TextField textField = new TextField();
textField.setPrefixComponent(TablerIcon.create("box"));
textField.setSuffixComponent(TablerIcon.create("box"));
Parts and CSS properties
Because all field components are built from a singular web component, they all share the following Shadow Parts and CSS Property values
Shadow parts
These are the various parts of the shadow DOM for the component, which are required when styling via CSS.
CSS properties
These are the various CSS properties that are used in the component, with a short description of their use.
Reflected attributes
The reflected attributes of a component are shown as attributes in the rendered HTML element for the component in the DOM. This means that styling can be applied using these attributes.
Dependencies
This component relies on the following components - see the related article for more detailed styling information:
Topics
📄️ ColorField
The ColorField component is a powerful and versatile tool designed to provide an intuitive and interactive way to explore and select colors within your application. Whether you're designing a user interface, creating visualizations, or enhancing user experience, the ColorField component offers a seamless and efficient approach to working with colors.
📄️ DateField
The DateField is a user interface component that allows users to input or select dates. It provides an intuitive and efficient way to handle date-related information in various applications. This section outlines the best practices for using the DateField component effectively.
📄️ DateTimeField
The DateTimeField class provides a user interface component that allows the user to enter both a date and a time, including the year, month, and day, as well as the time in hours and minutes. It offers the flexibility to validate the input or use a special date-time picker interface.
📄️ NumberField
The NumberField component can be used to accept numerical input from the user. It ensures that only valid numeric values are entered and provides a convenient interface for inputting numbers.
📄️ PasswordField
The PasswordField component provides a way for the user to securely enter a password. The element is presented as a one-line plain text editor control in which the text is obscured so that it cannot be read, usually by replacing each character with a symbol such as the asterisk ("*") or a dot ("•"). This character will vary depending on the user agent and operating system.
📄️ TextField
The TextField component allows users to enter and edit text in a single line. It can be configured to display a specific virtual keyboard, such as a numeric keypad, email input, telephone input, or URL input. The component also provides built-in validation to reject values that do not adhere to the specified type.
📄️ TimeField
TimeField is a user interface component that allows users to input or select times. It provides an intuitive and efficient way to handle time-related information in various applications. This section outlines the best practices for using the TimeField component effectively.