Auxx.ai

Form Component

Render type-safe forms with automatic validation in your Auxx app dialogs.

The Form, FormField, and FormSubmit components render a form from a schema with automatic validation and type-safe submission. Import from @auxx/sdk/client.

src/contact-form.tsx
import { Forms, Form, FormField, FormSubmit } from '@auxx/sdk/client'

const schema = {
  name: Forms.string().placeholder('Full name').minLength(2),
  email: Forms.string().email().placeholder('[email protected]'),
}

export function ContactForm({ hideDialog }: { hideDialog: () => void }) {
  return (
    <Form
      schema={schema}
      onSubmit={async (values) => {
        // values is typed as { name: string, email: string }
        console.log(values.name, values.email)
        hideDialog()
      }}
      onError={(error) => console.error(error)}
    >
      <FormField name="name" label="Name" />
      <FormField name="email" label="Email" />
      <FormSubmit>Save Contact</FormSubmit>
    </Form>
  )
}

Form

The form wrapper. Manages state, validation, and submission.

PropertyTypeDescription
schemaFormSchemaThe form schema object
onSubmit(values: InferFormValues<S>) => void | Promise<void>Called with validated values on submit
onChange(values: Partial<InferFormValues<S>>) => voidCalled on any field change
onError(error: Error) => voidCalled on submission error
onValidationError(errors: Record<string, string>) => voidCalled when validation fails
defaultValuesPartial<InferFormValues<S>>?Initial field values
mode'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all'When to validate (default: 'onSubmit')
formIdstring?Form identifier

FormField

Renders a single form field. The field type (text input, select, checkbox, etc.) is automatically determined from the schema.

<FormField name="email" label="Email Address" description="We'll never share your email." />
PropertyTypeDescription
namestringKey matching the schema field name
labelstringField label text
placeholderstring?Override the schema placeholder
descriptionstring?Help text below the field
disabledboolean?Disable the field

FormSubmit

The submit button. Automatically shows a loading state during async submission.

<FormSubmit loadingText="Saving..." variant="default">
  Save
</FormSubmit>
PropertyTypeDescription
childrenstringButton label
variant'default' | 'outline' | 'destructive' | 'secondary' | 'ghost'Button style
loadingTextstring?Text shown during submission
disabledboolean?Disable the button

Form ref

Access the form imperatively via a ref:

import { useRef } from 'react'

function MyForm() {
  const formRef = useRef(null)

  return (
    <>
      <Form ref={formRef} schema={schema} onSubmit={handleSubmit}>
        <FormField name="name" label="Name" />
      </Form>
      <Button label="Reset" onClick={() => formRef.current?.reset()} />
      <Button label="Submit" onClick={() => formRef.current?.submit()} />
    </>
  )
}
MethodDescription
reset()Reset all fields to defaults
setValue(name, value)Set a field value programmatically
validate()Run validation, returns Promise<boolean>
getValues()Get current form values
submit()Trigger form submission