Skip to content

TkxAutoForm

TkxAutoForm renders a complete, working form from a declarative FormSchema — no manual field wiring. It is the runtime counterpart to TkxFormBuilder: the builder designs a schema (and emits it as JSON), TkxAutoForm renders one. Author the schema by hand, fetch it from an API, or pipe it straight out of the builder. You get validation, an accessible error summary, themed controls, and kernel-grade input sanitisation on submit.

import { TkxAutoForm } from 'tekivex-ui';
const schema = {
title: 'Contact',
fields: [
{ id: '1', type: 'text', name: 'name', label: 'Name', required: true },
{ id: '2', type: 'email', name: 'email', label: 'Email', required: true },
{ id: '3', type: 'textarea', name: 'note', label: 'Message' },
],
};
<TkxAutoForm schema={schema} onSubmit={(data) => console.log(data)} />

FormSchema, FormField, FormFieldType, FormFieldOption, and validateField are re-exported from the package root — import them from 'tekivex-ui' alongside TkxAutoForm.

PropTypeDefaultDescription
schemaFormSchemaThe form definition ({ title?, description?, fields }).
defaultValuesRecord<string, unknown>Initial values, keyed by field name.
onSubmit(data: Record<string, unknown>) => voidCalled with validated (and by default sanitised) values.
onChange(values: Record<string, unknown>) => voidCalled on every change with the current raw values.
submitLabelstring'Submit'Submit button text.
sanitizebooleantrueRun string values through the security kernel before onSubmit.
redactPIIbooleanfalseAdditionally redact PII (email, cards, SSN, phone, API keys) from strings.
validateOnBlurbooleantrueValidate a field on blur, not only on submit.
classNamestringClass on the <form> element.
styleCSSPropertiesInline style merged onto the <form>.

Each entry in schema.fields is a FormField:

KeyTypeDescription
idstringStable React key.
type'text' | 'email' | 'number' | 'textarea' | 'select' | 'radio' | 'checkbox' | 'date'Control to render.
namestringKey in the submitted data object.
labelstringField label.
placeholderstring?Placeholder / checkbox inline label.
helpTextstring?Hint rendered under the control.
requiredboolean?Marks the field required (renders *).
optionsFormFieldOption[]?{ label, value }[] for select / radio.
min / maxnumber?Min/max for number & date; min/maxLength for text.
patternstring?Regex (text inputs), authored as a string for JSON safety.
  • Security on submit: when sanitize is on (the default), every string value is run through sanitizeUnicode → sanitizeString before it reaches onSubmit. With redactPII on, values additionally pass through scrubPII — useful when the payload is forwarded to an LLM. Non-string values pass through untouched. These kernel primitives emit SecurityEvents, so a TkxSecurityDashboard on the page reacts as users submit.
  • Accessible error summary: on a failed submit, an error summary with role="alert" is rendered and focused, and each entry links to (and focuses) the offending field. Field anchors are derived from name as #tkx-af-<name>, so field names must be unique within the form.
  • The <form> uses noValidate; validation is driven entirely by validateField, not the browser. validateOnBlur controls whether a field is re-checked on blur in addition to the submit pass.
  • onChange reports the raw (un-sanitised) values; only the onSubmit payload is hardened.

src/components/TkxAutoForm.tsx