External Submit
Form with an external submit button using the form ID.
"use client";
import { Button } from "@tilt-legal/cubitt-components/button";
import { z } from "zod";
import { FormBuilder } from "@tilt-legal/cubitt-components/form-builder";
const schema = z.object({
name: z.string().min(1, "Required"),
});
const formDefs = [
{
kind: "field",
name: "name",
label: "Name",
component: "text",
size: "full",
},
] as const satisfies FormDefs;
export default function ExternalSubmitForm() {
const formId = "my-form";
return (
<div className="space-y-4">
<FormBuilder.Single
id={formId}
schema={schema}
formDefs={formDefs}
defaultValues={{ name: "" }}
onSubmit={async (values) => console.log(values)}
/>
<Button type="submit" form={formId}>
Submit
</Button>
</div>
);
}How It Works
- Pass an
idprop – Assigns the ID to the underlying<form>element - Connect external button – Use
<Button form={id} type="submit">anywhere on the page - Auto-hide built-in button – When
idis provided withoutsubmitLabel, the default button is hidden
You can also use submitRef for imperative control:
const submitRef = useRef<() => void>(null);
<FormBuilder.Single submitRef={submitRef} ... />
<Button onClick={() => submitRef.current?.()}>Submit</Button>See the full API Reference
for id, submitRef, and submitLabel props.