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

Merging of FieldState's error and submitError #95

Closed
theneva opened this issue Mar 26, 2018 · 3 comments
Closed

Merging of FieldState's error and submitError #95

theneva opened this issue Mar 26, 2018 · 3 comments

Comments

@theneva
Copy link

theneva commented Mar 26, 2018

Are you submitting a bug report or a feature request?

Feature request

What is the current behavior?

FieldState has separate fields for error and submitError and no way to automatically merge them.

What is the expected behavior?

Field should be able to handle merging of the error and submitError automatically, so the components may only handle error.

From the perspective of all of my my projects', "merge" can be defined as "give submitError precedence". That is:

function merge(error, submitError) {
 if (submitError) {
  return submitError;
 }

 return error;
}

I don't really see a case where you would have both a valuation error (error) and a submission error (submitError), so perhaps they could just be one and the same from the get-go.

However, if that's not an option (I realise that it is possible to have both validation and submission errors at the same time), this could be introduced as a non-breaking change by simply allowing a prop like mergeErrors?: boolean, or even mergeErrors?: (validationError: ?any, submissionError: ?any) => resolvedError?: any—or both.

What's your environment?

This feature does not exist in the lastest release (4.4.0 at the time of writing).

@erikras
Copy link
Member

erikras commented Apr 12, 2018

This doesn't seem like a concern this library should dictate. Your concern is that you find yourself doing a lot of this? (react jsx syntax)

<div>
  {(error || submitError) && <Error>{error || submitError}</Error>}
</div>

and you'd rather just do

<div>
  {mergedError && <Error>{mergedError}</Error>}
</div>

?

@theneva
Copy link
Author

theneva commented Apr 12, 2018

Thanks for your response!

To be honest, this issue was a bit… misguided. We've actually implemented submitError handling into our form library now instead of just theorycrafting.

We realised that it's correct (in our case) to always show the field validation error when present (because we default to disabling the submit button if there are any errors), and only show the submitError if the field validation passes.

I no longer believe it possible to "solve" this "problem" (if there even is one anymore) in a way that works for (or even helps) everyone in this library, so I'll just close it.

@theneva theneva closed this as completed Apr 12, 2018
@lock
Copy link

lock bot commented Apr 12, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants