textArea 文本域

textArea 一个支持输入多行文本的区域。

XML 元素

textArea

Java 类

JmixTextArea

基本用法

当输入可能跨越多行(例如评论或描述)时,请使用 textArea。

<textArea id="textArea" value="Great job. This is excellent!" label="Comment"
          valueChangeMode="EAGER" maxLength="140" helperText="29/140"/>
<textArea id="textArea2" value="Everything you do works great!" label="Additional comment"/>

如果未设置固定高度,textArea 会根据内容自动调整高度。默认高度和最小高度是两行文字。

数据感知的 textArea

使用 dataContainer 和 property 属性将 textArea 与一个实体属性绑定。数据容器提供实体实例,property 表示需要使用该组件编辑的属性。

数据感知的 textArea 示例:

XML
<data>
    <instance id="orderDc"
              class="io.jmix.uisamples.entity.Order"
              fetchPlan="_local"/>
</data>
<layout>
    <textArea id="textArea" label="Order description"
              dataContainer="orderDc" property="description"/>
    <hbox>
        <span text="Value in the container:"/>
        <span id="spanValue"/>
    </hbox>
</layout>
Java
@ViewComponent
protected InstanceContainer<Order> orderDc;
@ViewComponent
protected Span spanValue;

@Autowired
protected Metadata metadata;

@Subscribe
protected void onInit(InitEvent event) {
    Order order = metadata.create(Order.class);
    order.setDescription("Deliver as quickly as possible.");
    orderDc.setItem(order);
}

@Subscribe("textArea")
protected void onTextAreaValueChange(ComponentValueChangeEvent<JmixTextArea, String> changeEvent) {
    spanValue.setText(orderDc.getItem().getDescription());
}

确保需要绑定的实体属性为字符串类型。与 textField 文本框 不同,textArea 是专门为处理文本数据而设计的。

大小可调

配置一个可调整大小的 CSS 类,让用户可以水平、垂直或两个方向调整文本区域的大小。在样式表中设置相应的 resize 值并使用溢出处理。

XML
<textArea id="textArea" label="Standard TextArea"/>
<textArea id="resizableBothTextArea" label="Resizeable TextArea"
          classNames="resizable-both"
          themeNames="helper-above-field"
          helperText="Both direction"/>
<textArea id="resizableVerticalTextArea" label="Resizeable TextArea"
          classNames="resizable-vertical"
          themeNames="helper-above-field"
          helperText="Vertical direction"/>
<textArea id="resizableHorizontalTextArea" label="Resizeable TextArea"
          classNames="resizable-horizontal"
          themeNames="helper-above-field"
          helperText="Horizontal direction"/>
CSS
.resizable-both {
    resize: both;
    overflow: auto;
    padding-bottom: unset;
}

.resizable-vertical {
    resize: vertical;
    overflow: auto;
    padding-bottom: unset;
}

.resizable-horizontal {
    resize: horizontal;
    overflow: auto;
    padding-bottom: unset;
}

样式版本

使用 themeNames 属性配置一个或多个样式。

样式 描述 支持的主题

small

组件尺寸较小

Aura, Lumo

align-left

字段值左对齐

Aura, Lumo

align-center

字段值居中

Aura, Lumo

align-right

字段值右对齐

Aura, Lumo

helper-above-field

帮助文字显示在字段上方,标题下方。

Aura, Lumo

XML 属性

下面是 textArea 的特殊属性:

名称 描述 默认值

clearButtonVisible

设置组件是否显示清除按钮。

false

maxRows

设置最大行数。

—

minRows

设置最小行数。

2

autoselect

设置当组件获得焦点时,是否自动选中文本。

—

trimEnabled

如果为 true,组件会去掉输入开头和结尾的空格。例如:" aaa bbb " 将保存为 "aaa bbb"。在使用 EAGER、LAZY 或 TIMEOUT valueChangeMode 时,需考虑与 trimEnabled 的相互作用。可以通过 jmix.ui.component.default-trim-enabled 属性在应用程序级别配置此设置。

—

下面是 textArea 支持的其他通用属性:

事件和处理器

下面是 textArea 的特殊事件和处理器:

名称 描述

validator

验证组件的值。

下面是 textArea 支持的其他通用事件:

XML 内部元素

一个 textArea 可以包含 tooltip、prefix、suffix 和 validator 作为其内部元素。

参考