fix(nodes): reset edit form with initial values on open#53
Open
web-ppanel wants to merge 2 commits into
Open
Conversation
… input error When a node was created without tags (tags is null from API), editing it caused an 'Invalid input' validation error because null failed z.array(z.string()) validation. - Use z.preprocess to coerce null/undefined to [] in zod schema - Add normalizeValues() helper to ensure tags is always [] before spreading initialValues into form defaultValues and reset() Closes #51
When the Edit button is clicked, form.reset() was called with no
arguments, clearing all fields to default values. Because initialValues
(the row object) didn't change, the useEffect that repopulates the form
never re-fired, leaving the form blank. Saving then triggered Zod
validation errors ('Invalid input') since required fields were empty.
Fix: pass the normalized initialValues into form.reset() on the trigger
onClick, so the edit sheet always opens pre-filled with the current
node's data.
Closes #51
✅ Deploy Preview for ppane-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When clicking the Edit button on a node,
form.reset()was called with no arguments, clearing all fields to their default values (empty strings,port: 0, etc.). SinceinitialValues(the row reference) did not change, theuseEffectthat repopulates the form frominitialValuesnever re-fired — so the edit sheet opened with a blank form.Submitting the blank form triggered Zod validation errors, shown as "Invalid input" toasts.
Fix
Pass the normalized
initialValuesintoform.reset()on trigger click, so the edit sheet always opens pre-filled with the current node data.Closes #51