Method Signatures and Parameters | |
Jt.textInput(String label) | label (String) A short label explaining to the user what this input is for. Markdown is supported, see |
Chainable builder methods | |
value(String value) | The text value of this widget when it first renders. Defaults to empty string. |
maxChars(Integer maxChars) | The maximum number of characters allowed in the text input. |
type(String type) | Can be |
help(String help) | A tooltip that gets displayed next to the text. If this is |
autocomplete(String autocomplete) | An optional value that will be passed to the element's autocomplete property. If unspecified, this value will be set to |
placeholder(String placeholder) | An optional string displayed when the text input is empty. |
disabled(boolean disabled) | Disable the text input if set to true. When disabled, users cannot interact with the widget. |
labelVisibility(JtComponent.LabelVisibility labelVisibility) | The visibility of the label. The default is |
icon(String icon) | An icon to display with the error message. The following values are valid:
null (default), no icon is displayed.
|
width(String width) | Controls the widget width. Can be |
width(int widthPixels) | The width of the element in pixels. The element will have a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container. |
onChange(function.Consumer<String> onChange) | An optional callback invoked when the text input's value changes. The value passed in the callback is the previous value of the component. |
key(String key) | A string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key. |
No description | |
use() | Put the widget in the app, in the |
use(JtContainer container) | Put the widget in the app, in the provided container. |
Returns after .use() | |
(string) | The current string value of the component. |
Examples
Simple text input
import tech.catheu.jeamlit.core.Jt;
public class TextInputApp {
public static void main(String[] args) {
String name = Jt.textInput("Your name").use();
if (!name.isEmpty()) {
Jt.text("Hello, " + name + "!").use();
}
}
}
Text input with validation
import tech.catheu.jeamlit.core.Jt;
public class ValidatedTextInputApp {
public static void main(String[] args) {
String email = Jt.textInput("Email address")
.placeholder("Enter your email")
.use();
if (!email.isEmpty() && !email.contains("@")) {
Jt.error("Please enter a valid email address").use();
} else if (!email.isEmpty()) {
Jt.text("Valid email: " + email).use();
}
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.