目录

input

Represents an input box.

Since: 1.0.0

Attributes

Name Type Default Value Mandatory Description
value string - No Initial content of the input box.
focus boolean false No Whether the input box has the focus.
type string text No

Input type. Valid values:

- text: text input.

- number: number input.

confirm-type string done No

Text displayed on the bottom-right button of the keyboard. This property takes effect only when type is set to text. Valid values:

- send: The text on the bottom-right button of the keyboard is Send.

- search: The text on the bottom-right button of the keyboard is Search.

- next: The text on the bottom-right button of the keyboard is Next.

- go: The text on the bottom-right button of the keyboard is Go.

- done: The text on the bottom-right button of the keyboard is Done.

password boolean false No Whether it is a password.
placeholder string - No Placeholder when the input box is empty.
placeholder-style string - No

Placeholder style.

Since: 1.0.9

disabled boolean false No Whether the component is disabled.
maxlength number 140 No Maximum input length (-1: no limitation on length).
bindinput eventhandle - No Event triggered when the keyboard is used for input.
bindfocus eventhandle - No Event triggered when the input box gains focus.
bindblur eventhandle - No Event triggered when the input box loses focus.
bindconfirm eventhandle - No Event triggered when the Done button is pressed.
placeholder-class string input-placeholder No

Placeholder style class.

Since: 1.0.9

Example:

HXML file:

<view class="page-section page-section-gap">
  <view class="ascf-cells__title">bindinput obtains the input value in real time: {{inputValue}}</view>
  <view class="ascf-cells ascf-cells_after-title">
    <view class="ascf-cell ascf-cell_input">
      <input class="ascf-input" bindinput="bindInputEvent" placeholder="Event triggered when the keyboard is used for input."/>
      <input class="ascf-input" bindfocus="bindFocusEvent" placeholder="Event triggered when the input box gains focus."/>
      <input class="ascf-input" bindblur="bindBlurEvent" placeholder="Event triggered when the input box loses focus."/>
      <input class="ascf-input" bindconfirm="bindConfirmEvent" placeholder="Event triggered when the Done button is pressed."/>
    </view>
  </view>
</view>

JavaScript file:

Page({
  data: {
    inputValue: "",
  },
  bindInputEvent(event) {
    // Example of event.detail: {"value":"", cursor: 1}
    console.info('Event triggered when the keyboard of the input component is used for input. Carried value: ', event.detail.);
    this.setData({
      inputValue: event.detail,
    });
  },
  bindFocusEvent(event) {
    // Example of event.detail: {"value":""}
    console.info('Event triggered when the input box of the input component gains focus. Carried value: ', event.detail)
  },
  bindBlurEvent(event) {
    // Example of event.detail: {"value":""}
    console.info('Event triggered when the input box of the input component loses focus. Carried value: ', event.detail)
  },
  bindConfirmEvent(event) {
    // Example of event.detail: {"value":""}
    console.info('Event triggered when the Done button of the input component is pressed. Carried value: ', event.detail.');
  }
});