fix(dashboard): surface validation errors when the submit button is disabled#4868
Conversation
…isabled Detail-page forms disable the submit button when the form is invalid, but the reason was never shown on the page (only logged). A field with an invalid value — typically a custom field whose stored value or default fails validation — left the button silently disabled. Add a shared FormErrorSummary banner (rendered for every detail page) that lists the blocking fields, and validate existing entities on load so pre-existing invalid values surface immediately instead of only after the user edits a field. Fixes vendurehq#4741
Drives a product form into an invalid state via a patterned custom field and asserts the FormErrorSummary banner appears, the submit stays disabled, and both clear once the value is corrected. Fails without the fix. Relates to vendurehq#4741
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughA new Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/dashboard/e2e/tests/regression/issue-4741-form-error-summary.spec.ts`:
- Around line 5-13: Update the header comment in the affected Dashboard E2E spec
to match the required issue-reference format. In the test file near the top of
the regression spec, replace the URL-style multi-line issue note with a single
comment starting with `// `#4741` — ...` and keep the rest of the description
concise. Use the existing `issue-4741-form-error-summary.spec.ts` test and its
`FormErrorSummary`/`oss540NumericCode` context to locate the comment, and ensure
it follows the Dashboard E2E guideline for
`packages/dashboard/e2e/**/*.spec.ts`.
In `@packages/dashboard/src/lib/components/shared/form-error-summary.tsx`:
- Around line 52-55: The humanizeFieldName() helper is stripping all path
context by only using the last segment, which makes repeated or nested fields
indistinguishable. Update form-error-summary.tsx so this function preserves
enough of the original field path to disambiguate entries like
translations.0.name vs translations.1.name while still humanizing the final
label; keep the unique path context in the output and adjust the existing
transformation in humanizeFieldName().
In `@packages/dashboard/src/lib/framework/form-engine/use-generated-form.tsx`:
- Around line 168-179: The validation effect in useGeneratedForm currently runs
only when entity?.id changes, so it can fire before the derived form values are
fully built. Update the useEffect that calls form.trigger() to also wait for the
form shape inputs used to derive values (such as
serverConfig?.availableLanguages and the schema-driven inputs around the values
computation) so it reruns when that shape settles for the same entity. Keep the
one-time-per-entity behavior, but ensure the trigger happens after the generated
values are complete enough to catch hidden invalid translations/custom fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1920dc2c-5caf-4de3-929c-e8e2c08be6d4
📒 Files selected for processing (7)
packages/dashboard/e2e/fixtures/e2e-shared-config.tspackages/dashboard/e2e/tests/regression/issue-4741-form-error-summary.spec.tspackages/dashboard/src/i18n/locales/en.popackages/dashboard/src/lib/components/shared/form-error-summary.tsxpackages/dashboard/src/lib/framework/form-engine/use-generated-form.tsxpackages/dashboard/src/lib/framework/layout-engine/page-layout.tsxpackages/dashboard/src/lib/index.ts
…shape settles Address CodeRabbit review on vendurehq#4868: - Keep path context in the error summary so repeated/nested fields are distinguishable (e.g. "Translations #1 › Name" instead of "Name"). - Re-run the on-load validation when the schema/available languages settle, not only on entity id, so hidden invalid custom fields/translations surface even if the entity loads before those inputs. - Use the mandated issue-reference comment format in the regression spec. Relates to vendurehq#4741
|
Thanks @coderabbitai — all three addressed in 2a0aaf1:
Verified: e2e regression still passes on the branch (and fails without the fix), |
|
Tip For best results, initiate chat on the files or code changes.
(∩`-´)⊃━☆゚.*・。゚ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
@grolmus can you include screenshots and/or screen recording of how this looks? |
|
|
@michaelbromley Ran the TL;DR: both pass, no blockers.
|
|
All contributors have signed the CLA ✍️ ✅ |
…ct-dashboard-operation-buttons-are-frequently-disabled
Relates to OSS-540
…ation loop Relates to OSS-540
CI fixes after updating from
|
…buttons-are-frequently-disabled Regenerate i18n catalogs (lingui extract) to resolve .po conflicts







Summary
Detail-page forms in the dashboard disable the submit button whenever the form is invalid (
disabled={!isDirty || !isValid || isPending}), but there was no on-page indication of why. When a field — very often a custom field whose stored value or generated default fails validation — is invalid, the button silently stayed disabled and the only trace was aconsole.log. This is the behaviour reported in #4741: "operation buttons are frequently disabled with no on-page prompts."This PR keeps the disabled-button logic and the backend untouched and instead surfaces the reason.
Root cause
useGeneratedFormbuilds a zod schema from the entity's input type + custom fields and runs react-hook-form inmode: 'onChange'. An invalid value (e.g. a custom field whose value violates itspattern/min/max/enum) makesformState.isValidfalse, disabling submit. Field-level errors only render once a field is touched, so on a freshly-loaded edit page nothing was shown — the button just looked broken.Change
FormErrorSummary(lib/components/shared/form-error-summary.tsx): a destructiveAlertlisting the fields that block saving, rendered once in the sharedPageContentWithOptionalForm, so every detail page (generated and bespoke, e.g. product variants) gets it for free. Flattens nested RHF errors (customFields.*, array paths likestockLevels.0.stockOnHand) and never renders empty while the form is invalid (errors without a message fall back to a translated generic; the reservedrootbucket is skipped).use-generated-form.tsx):form.trigger()runs once per loaded entity (keyed onentity.id) so pre-existing invalid values surface immediately instead of only after the user pokes a field.zodResolver(schema)and removed two debugconsole.logs.FormErrorSummaryfrom the public API (lib/index.ts).No change to the
disabledcondition, the mutations, or the backend. A valid form (nothing to save) shows no banner — the button is still correctly disabled with no false alarm.Test plan
Automated —
e2e/tests/regression/issue-4741-form-error-summary.spec.ts:oss540NumericCodeproduct custom field (pattern^[0-9]*$, empty allowed so other tests are unaffected).abcdisables it and shows the summary banner with the reason; correcting to12345clears the banner and re-enables Create.Manual (chrome-devtools, before/after screenshots attached on the Linear issue OSS-540): edit page of an entity whose custom field value is invalid — before: Update disabled, no prompt; after: banner + field-level error explain exactly which field and why. Verified a valid page (Zone) shows no banner.
Out of scope / follow-ups
Value must match pattern: …, etc., fromform-schema-tools.ts) are not yet wrapped for i18n — a pre-existing gap now made more visible. Worth a dedicated follow-up.Fixes #4741
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.