chuijsdocs

TextInput

Однострочное текстовое поле.

Однострочное текстовое поле.

const input = new TextInput({
    name: 'name', title: 'Имя', placeholder: 'Введите имя', required: true
});
input.setValue('Пётр');

Опции:

  • name
  • title
  • placeholder
  • width
  • required
  • value
  • disableFocus
  • inputListener
  • focusListener
  • blurListener
  • minLength
  • maxLength
  • pattern
  • type
  • validate
  • messages

API:

  • getName()
  • getTitle()
  • getValue()
  • setValue()
  • setDisabled()
  • setErrorMessage()
  • addInputListener()
  • addFocusListener()
  • addBlurListener()
  • set()

Валидация полей. Поля ввода принимают правила и получают единый контракт validate() / setError(text) / clearError() / getError() (такие же методы есть у TextArea

  • NumberInput
  • EmailInput
  • PasswordInput
  • Select
  • ComboBox
  • CheckBox
  • Toggle):
const input = new TextInput({
    name: 'email', title: 'Email', required: true,
    pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
    messages: { pattern: 'Нужен вид user@example.com' }
});
input.validate();      // { valid: false, rule: 'pattern', message: '…' }
input.setError('…');   // красная рамка + текст ошибки + aria-invalid
input.clearError();    // убрать ошибку
input.getError();      // текущий текст ошибки или undefined

Правила:

  • required
  • min
  • max (числа)
  • minLength
  • maxLength
  • pattern (RegExp или строка)
  • type: 'email' (готовый email-паттерн)
  • validate(value) — своя функция

возвращающая текст ошибки; messages переопределяет тексты по правилам (шаблоны вроде {minLength}).

Состав в коде — скан framework/components/chui_inputs/chui_text/text.js
Файл
framework/components/chui_inputs/chui_text/text.js
Экспорт
TextInput
Классы
  • TextInput — 10 методов: addBlurListener(), addFocusListener(), addInputListener(), getName(), getTitle(), getValue(), set(), setDisabled(), setErrorMessage(), setValue()
Свои стили
styles.css → тег chUiJS_TextInput
Зависимости
chui_animations, chui_functions, chui_validate
Методы из модулей
validate() ← chui_validate, getRules() ← chui_validate, setError() ← chui_validate, clearError() ← chui_validate, getError() ← chui_validate
Внешние пакеты
randomstring
destroy()
нет
Доступность
—
Локализация
—

Определяется автоматически по исходникам (docs/build.js), а не описано автором. Модули framework/modules/* — общая инфраструктура, а не часть компонента.