Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trigger validation netsted field #11336

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

sungh0lim
Copy link

@sungh0lim sungh0lim commented Dec 24, 2023

To fix #10862 .

To ensure that an empty array [] is considered a valid value and correctly triggers validation when shouldValidate is set to true, I add the condition isEmptyNonPrimitive.

I want to add tests for the cases of an empty object and an empty array in setValue.test.tsx, but I'm not sure what to compare. Can you help me with this?

Copy link

codesandbox bot commented Dec 24, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@sungh0lim sungh0lim changed the title Trigger validation netsted field fix: trigger validation netsted field Dec 24, 2023
bluebill1049
bluebill1049 previously approved these changes Jan 13, 2024
Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for the contribution. Sorry I have been busy and completely miss the PR>

@bluebill1049
Copy link
Member

looks like test is failed.

<button
type="button"
onClick={() => {
setValue('item1.positions', [{ activities: [] }]);
Copy link
Author

Choose a reason for hiding this comment

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

@bluebill1049 To check #10862 . How about this?

setValue("item1.positions", [{ activities:[] }], {
  shouldValidate: true
});

setValue("item2.positions.0.activities",[], {
  shouldValidate: true
});

Copy link
Member

Choose a reason for hiding this comment

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

yea, i did. I think it would be rather difficult to set inputs to empty values. if they are deeply nested. so it's better let the users at the app level doing that setValue within a loop. thanks a lot for your help and contribution tho.

Copy link
Author

@sungh0lim sungh0lim Jan 17, 2024

Choose a reason for hiding this comment

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

How about incorporating this change into'should be able to set to empty array value' tests? The existing test failed because only one side(item1.positions) was modified (item2.positions not modified).
If you confirm, I will change it.

Copy link
Author

Choose a reason for hiding this comment

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

@bluebill1049 Please check it.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, miss the pr. please update PR and I will review it again.

Copy link
Author

Choose a reason for hiding this comment

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

I updated it!

@bluebill1049
Copy link
Member

thank you for your contribution! <3

@sungh0lim
Copy link
Author

@bluebill1049 Can it be merged into the main branch? It's been a long time since I was approved.

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.

issue: setValue an empty array to a nested field doesn't trigger validation when shouldValidate is true
2 participants