Skip to content

text

A single-line <input>. This is the default kind: leave kind out and you get one.

ts
{
  fields: [
    { name: 'title', displayName: 'Title' },
    { name: 'subtitle', displayName: 'Subtitle', placeholder: 'Optional' },
  ],
}
Rendered form

Values

Options

OptionTypeNotes
typestringMaps to the type attribute: 'password', 'number', 'email', 'url', …
placeholderReactive<string>Literal, or a function of the form context
autocompletestringMaps to the autocomplete attribute

Plus everything in the shared options.

Input types

ts
{ name: 'token', displayName: 'Access token', type: 'password' }
{ name: 'count', displayName: 'Copies', type: 'number' }

The value is always read back as a string, even for type: 'number'. Convert it where you use it:

ts
onConfirm: (values) => save({ copies: Number(values['count']) }),

Reactive placeholders

If the placeholder is a function, it is calculated again on every form update, so it can follow another field:

ts
{
  name: 'locator',
  displayName: 'Locator',
  placeholder: ({ data }) =>
    data['locatorType'] === 'chapter' ? 'e.g. 4' : 'e.g. 12–18',
}

Autocomplete

The <form> element is created with autocomplete="off", so the browser does not fill fields in automatically. Turn it back on for the single fields where you really want it, such as a real name or address field:

ts
{ name: 'email', displayName: 'Email', autocomplete: 'email' }

Values

getValue() returns the current text of the input, and the empty value is ''. If you set something that is not a string, it is converted in a sensible way: 0 becomes '0', null and undefined become '', and objects are converted to JSON.

ts
form.field('title')?.setValue('Field notes');
form.getValues()['title']; // 'Field notes'

Released under the MIT License.