getCollectionDefaultValues
getCollectionDefaultValues(
props):Record<string,unknown>
Defined in: packages/core/src/collections/utils.ts:29
Builds the defaultValues object for a TanStack Form instance from a collection.
When document is provided, uses the document’s field values (edit mode).
When omitted, falls back to each field’s defaultValue (create mode).
The returned object’s keys match the collection field keys.
Parameters
Section titled “Parameters”Input props.
collection
Section titled “collection”The collection whose fields define the form shape.
document?
Section titled “document?”TDocument | null
Optional existing document to populate values from when editing.
Returns
Section titled “Returns”Record<string, unknown>
A Record<fieldKey, value> ready to pass to useForm({ defaultValues }).
Example
Section titled “Example”// New document — uses field defaultsgetCollectionDefaultValues({ collection: postsCollection })// → { title: "", slug: "" }
// Existing document — uses document valuesgetCollectionDefaultValues({ collection: postsCollection, document: doc })// → { title: "Hello world", slug: "hello-world" }