Skip to content

fix Use field defaults from schema in v1 - #269

Open
danielcardoso5 wants to merge 5 commits into
mainfrom
v1-defaults-not-applied
Open

fix Use field defaults from schema in v1#269
danielcardoso5 wants to merge 5 commits into
mainfrom
v1-defaults-not-applied

Conversation

@danielcardoso5

@danielcardoso5 danielcardoso5 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Fixes default values not being taken into account when initializing a form like v0 did. Supports passing default values for base fields, nested fields and group-array items.

With the schema from #249:

before after
image image

Note

Medium Risk
Changes initial form state and conditional visibility for all consumers relying on missing defaults; behavior differs from v0 for explicit falsy initial values.

Overview
Restores v0-style default seeding so createHeadlessForm applies JSON Schema default values before the first field build, fixing conditionals (e.g. if/then) that depend on a defaulted field not resolving until after handleValidation.

A new fillDefaults helper walks the base schema: object properties, nested objects, and existing array items only. It sets default when the value is undefined—explicit falsy values like null are kept (documented as a v0 vs v1 migration difference). Defaults inside conditional sub-schemas are not applied. initialValues are not mutated.

MIGRATING.md adds a breaking-change note on default semantics; tests cover init-time conditionals, overrides, nested and group-array cases.

Reviewed by Cursor Bugbot for commit c9f151d. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/form.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 04472f1. Configure here.

Comment thread src/form.ts Outdated
@dragidavid

Copy link
Copy Markdown
Collaborator

Sorry for the delay @danielcardoso5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants