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 isEmpty check in validateField for custom field components #11179

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

Conversation

rvetere
Copy link

@rvetere rvetere commented Nov 10, 2023

With a custom built field component it can happen that the referenced element does not have a value attribute.
But the state is correctly set at the moment of validation.

In that case, the validateField function thinks the field is empty, because of this line:

isHTMLElement(ref) && ref.value === ''

I've added a test to show that behavior and it fails with the current implementation as it does in our case of a multi select field with downshift.js

I think we could improve the "is-empty-check" by increasing the priority of the inputValue - we don't need to check if the ref-element's value attribute is empty when we have a valid inputValue, right?

Copy link

codesandbox bot commented Nov 10, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@rvetere rvetere changed the title Fix isEmpty check in validateField for custom select components Fix isEmpty check in validateField for custom field components Nov 10, 2023
@@ -67,13 +66,18 @@ export default async <T extends FieldValues>(
const isRadio = isRadioInput(ref);
const isCheckBox = isCheckBoxInput(ref);
const isRadioOrCheckbox = isRadio || isCheckBox;
const isInputValueEmpty =
isUndefined(inputValue) ||
inputValue === null ||
Copy link
Member

Choose a reason for hiding this comment

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

so the additional check is just check null?

Copy link

stale bot commented Mar 13, 2024

Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️

@stale stale bot added the stale label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants