Toolforge Docs
DocsIO PrimitivesformInput

formInput

Creates a multi-field form with multiple inputs at once. All fields are validated together.

Usage

Form input

const userInfo = await io.formInput({
  title: 'User Registration',
  description: 'Please fill in your details',
  form: {
    firstName: {
      type: 'text',
      label: 'First Name',
    },
    lastName: {
      type: 'text',
      label: 'Last Name',
    },
    email: {
      type: 'text',
      label: 'Email',
      inputType: 'email',
    },
  },
})

Props

PropDescriptionTypeRequiredDefault
formThe form definition with named fieldsIOFormWithSearchHandlerYes
validationSchemaOptional validation schema for the form. If not provided, schemas are inferred from form field definitionsIOFormValidationSchema<T>Noundefined
maxRetryAttemptsMaximum retry attempts for invalid inputnumberNo5
titleOptional title for the formstringNoundefined
descriptionOptional description for the formstringNoundefined
defaultValuesOptional default values for the form fieldsPartial<IOFormOutput<T>>Noundefined

Returns

Returns a Promise<IOFormOutput<T>> where T is the form type. TypeScript infers the exact structure from the form definition, preserving field names and types.

Examples

Complete form example

Form input

const userInfo = await io.formInput({
  title: 'User Registration',
  form: {
    firstName: { type: 'text', label: 'First Name' },
    lastName: { type: 'text', label: 'Last Name' },
    email: { type: 'text', label: 'Email', inputType: 'email' },
    age: { type: 'number', label: 'Age', min: 18, max: 100 },
    country: {
      type: 'select',
      label: 'Country',
      options: [
        { label: 'United States', value: 'US' },
        { label: 'Canada', value: 'CA' },
      ],
    },
    bio: {
      type: 'text',
      label: 'Biography',
      mode: 'textarea',
      optional: true,
    },
  },
  defaultValues: {
    country: 'US',
  },
})

// TypeScript knows the structure:
// {
//   firstName: string
//   lastName: string
//   email: string
//   age: number
//   country: 'US' | 'CA'
//   bio?: string
// }

Form with search input

Form with search input

const orderForm = await io.formInput({
  form: {
    customer: {
      type: 'search',
      label: 'Customer',
      handleSearch: async (query) => {
        return await searchCustomers(query)
      },
    },
    product: {
      type: 'search',
      label: 'Product',
      mode: 'multiple',
      handleSearch: async (query) => {
        return await searchProducts(query)
      },
    },
    quantity: {
      type: 'number',
      label: 'Quantity',
      min: 1,
    },
  },
})

On this page