input

Input box

Property

TypeDefaultDescription
valueStringInitial contents.
nameStringComponent name, used for the form submission of obtained data.

type

String

text

The type of data that users can enter in the input field. Valid values are:

  • text:  Single-line text input.
  • number: Numbers (0-9) and hyphens (-).
  • digit: Numbers (0-9) and decimal points (.).
passwordBooleanfalseIs password type or not.
placeholderStringPlaceholder .
placeholder-styleStringSpecify placeholder style.
placeholder-classStringSpecify placeholder style class.
disabledBooleanfalseDisable or not.
maxlengthNumber140Maximum length.
cursorNumberCursor location when specifying focus.
onInputEventHandleTrigger input event on keyboard entry, event.detail = {value: value}.
onConfirmEventHandleTrigger on clicking keyboard completion, event.detail = {value: value}.
onFocusEventHandleTrigger on getting focus, event.detail = {value: value}.
onBlurEventHandleTrigger on losing focus, event.detail = {value: value}.

Note (For iOS):

Due to iOS system restrictions, the input component has the following known issues:

  • The cursor of input might be misaligned with the input element.
  • The keyboard might be hidden with long press onthe input.

To solve these issues, add enableNative={{false}} to the input element of your MiniProgram code to downgrade to pure HTML5 elements.

Now the enableNative property is set to false. In this case,the number type is no longer supported, and only text type input is supported for inputs.

Screenshot

c73aaa53f7d00257c6c0e82f2dbb8530.png

Sample Code

copy
<input maxlength="10" placeholder="maximum entered length 10" />
<input onInput="bindKeyInput" placeholder="entry synchronized to view"/>
<input password type="text" placeholder="This is a password entry box" />
copy
Page({
  data: {
    inputValue: '',
  },
  bindKeyInput(e) {
    this.setData({
      inputValue: e.detail.value,
    });
  },
});