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

Why is Controller fieldState naming inconsistent? #8195

Closed
GollyJer opened this issue Apr 15, 2022 · 5 comments · Fixed by #8202
Closed

Why is Controller fieldState naming inconsistent? #8195

GollyJer opened this issue Apr 15, 2022 · 5 comments · Fixed by #8202
Labels
feature request request a feature to be added

Comments

@GollyJer
Copy link

GollyJer commented Apr 15, 2022

In formState 👉 isValid - boolean - Set to true if the form doesn't have any errors.
In fieldState 👉 invalid - boolean - Invalid state for current input.

This threw me off a bit. Had to go to the docs to find the invalid return object.

Just curious if this is a purposeful difference, and if so what is the reason?

Best,
Jeremy

@GollyJer GollyJer added feature request request a feature to be added waiting-up-vote Waiting for votes from the community. labels Apr 15, 2022
@Moshyfawn
Copy link
Member

Moshyfawn commented Apr 15, 2022

Hey, @GollyJer!

I've updated the API to include isValid convention for the field's validation state.

@bluebill1049 u can freely reject #8196 if the API is supposed to be different between the form validation state and the field's one

@Moshyfawn Moshyfawn added this to In progress in React Hook Form Apr 15, 2022
@bluebill1049
Copy link
Member

Thanks, guys for the input. @Moshyfawn I think this will be introducing a breaking change to the existing version. This is actually by design, we have form level state isValid which leads by when the user subscribes to the form validity. For field level, at the moment we don't trigger every field input and flush down errors that include onChange mode, that's why the initial state of input will remain invalid as false unless an error state appears. I understand this is not a consistent API, but unless we start to support another form state such as validateFields, we will have to keep the API as invalid for now.

@Moshyfawn
Copy link
Member

Moshyfawn commented Apr 16, 2022

I see your point, @bluebill1049! It is a breaking change and having V8 on the horizon, I understand how inconvenient it would be.

Maybe we can re-visit the API consistency once the V8 is out the door.

One additional thing: what's the point of fieldState.invalid again? In docs it's usually show to check for the errors.fieldName and not much of fieldState.invalid usage. Is the invalid state really necessary?

{errors.fieldName && <p role="alert">{errors.fieldName.message}</p>}

@bluebill1049
Copy link
Member

yes, @Moshyfawn let's deprecate that field state, I don't think it's server too much value. if you want to adjust your PR and point to v8?

@Moshyfawn
Copy link
Member

Sounds good!

bluebill1049 pushed a commit that referenced this issue Apr 16, 2022
* ♻️ refactor(fieldstate): remove fieldState.invalid

Closes: #8195

* 🔧 chore(fieldstate): update tsdocs field description

* ✅ test(fieldstate): remove fieldState.invalid tests

* 🔧 chore(fieldstate): update api report
@Moshyfawn Moshyfawn linked a pull request Apr 16, 2022 that will close this issue
@bluebill1049 bluebill1049 moved this from In progress to Done in React Hook Form Apr 17, 2022
@bluebill1049 bluebill1049 removed the waiting-up-vote Waiting for votes from the community. label Jul 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature request request a feature to be added
Projects
3 participants