Site color

Choose your site’s color palette.

Saved on this device.

AppForm

AppFormForm composition

Compose a clear path from input to outcome. A themed native form with validation and submission in your control.

Forms & input

Save a project

Edit the project name, save it locally, then reset. The handler explicitly checks native constraints because AppForm renders novalidate.

AppForm in contextCOMPOSITION

Edit the project name, save a local preview, and reset the form. No request leaves this page.

<RegorApp id="app-form-demo" src="./playground.ts"/>
import {
  defineButtonComponents,
  defineFlexComponents,
  defineFormComponents,
  defineFormInputField,
  definePanelComponents,
} from '@purestack/ts-components'
import { createApp, defineComponent, html, type Ref, ref } from 'regor'
import { mountFormAppearanceGalleries } from '../appearance'

export interface AppFormExample {
  projectName: Ref<string>
  savedProject: Ref<string>
  save: (event: Event) => void
  reset: () => void
}

const appFormExampleTemplate = html`<Panel bodyClass="p-4">
  <AppForm @submit.prevent="save" @reset.prevent="reset">
    <FormInputField
      id="app-form-project"
      name="project"
      label="Project name"
      :model="projectName"
      :required="true"
      minlength="3"/>
    <FormMeta>
      <FormSubmit label="Save project" tone="accent"/>
      <Btn type="reset" variant="outline">Reset</Btn>
    </FormMeta>
    <FormStatus tone="success" :hidden="!savedProject">
      Saved locally: {{ savedProject }}
    </FormStatus>
  </AppForm>
</Panel>`

function createAppFormExample(): AppFormExample {
  const projectName = ref('Project docs')
  const savedProject = ref('')
  return {
    projectName,
    savedProject,
    save: (event) => {
      const form = event.target as HTMLFormElement
      if (!form.reportValidity()) return
      savedProject(String(new FormData(form).get('project') ?? ''))
    },
    reset: () => {
      projectName('Project docs')
      savedProject('')
    },
  }
}

const component = defineComponent<AppFormExample>(appFormExampleTemplate, {
  context: createAppFormExample,
})

createApp(
  {
    components: {
      AppFormExample: component,

      ...defineFlexComponents(),
      ...definePanelComponents(),
      ...defineButtonComponents(),
      ...defineFormComponents(),
      ...defineFormInputField(),
    },
  },
  { selector: 'app#app-form-demo', template: html`<AppFormExample/>` },
)

mountFormAppearanceGalleries()

Compose a form surface

Choose the surrounding treatment independently of the fields. This disabled example shows structure without submitting data.

Connect the form to your application’s submit handler.
<AppForm method="post" tone="neutral" variant="outline" class="p-4">
  <FormInputField
    id="form-structure-name"
    name="name"
    label="Workspace name"
    placeholder="Your workspace"
    :disabled="true"
  />
  <FormStatus>Connect the form to your application’s submit handler.</FormStatus>
</AppForm>

All semantic tones

All ten tones are visible at once. The control’s label and content explain the intent independently of color.

All ten semantic tonesCOMPOSITION

Each sample is interactive and keeps its own local state. Switch the site theme to compare both palettes.

All visual variants

All eighteen supported treatments, shown in accent. Tone and variant are independent, so any treatment can be combined with a semantic tone.

All eighteen visual variantsCOMPOSITION

Each sample is interactive and keeps its own local state. Switch the site theme to compare both palettes.

Composition, validation, and submission

Feature Visible example
action and method Native endpoint attributes; the local example intercepts submit.
Default slot Inputs, metadata, help links, divider, and feedback can be composed freely.
Validation AppForm uses novalidate. Call reportValidity in your submit handler when you want native validation.
Form data Give each contributing field a name, then read new FormData(form).
Reset The live example resets its refs explicitly; resetting a native form alone does not define application state.
Appearance Every tone and variant is visible above.
<AppForm action="/api/projects" method="post" @submit.prevent="save">
  <FormInputField id="project-name" name="project" label="Project name" :model="projectName" :required="true"/>
  <FormMeta><FormSubmit label="Save project" tone="accent"/><FormAssistLink href="/guides/" label="Need help?"/></FormMeta>
  <FormStatus :hidden="!message">{{ message }}</FormStatus>
</AppForm>

Behavior and accessibility

AppForm always renders novalidate. Use reportValidity or your own validation in a submit handler. Named controls participate in FormData; disabled controls do not. Reset reactive refs explicitly when handling reset in a Regor app.

API reference

AppForm contract

Props below are the public template API. RefOrValue accepts a literal or a reactive ref; bind refs with a colon-prefixed attribute. Native attributes and events can be passed through the component root.

action

RefOrValue<string>
Default
not set

Native submission URL, resolved against the SSG base path. Browser examples intercept submit to keep data local.

method

RefOrValue<string>
Default
browser default: get

Native form method. Set post when your endpoint expects a request body.

tone

RefOrValue<SemanticTone>
Default
inherited

Semantic intent: neutral, accent, secondary, info, success, warning, danger, feature, custom or ghost. The active skin supplies the colors.

variant

RefOrValue<ComponentVariant>
Default
none

Visual treatment. Accepts solid, surface, surfaceAlt, spotlight, glass, flat, flatAlt, flatSolid, outlineFill, outline, subtle, subtleBtn, link, sheen, underline, rail, bracket or none.

Composition

Default slot: native fields and form components. Native submit and reset events bubble normally. Register defineFormComponents; register each field family separately.