Closed youssef-lr closed 1 year ago
Triggered auto assignment to @sophiepintoraetz (AutoAssignerTriage
), see https://stackoverflow.com/c/expensify/questions/4749 for more details.
Not overdue. Working on making this work properly with some new changes in the API, then I'll update the issue with the final changes that must be added to Form.
Add a getErrorMessage function to Form that extracts the latest error message from the errors object.
Should we be showing all possible errors messages from the errors object?
Rename setErrorMessage in actions/FormActions.js to setErrors.
👍
Add an optional prop isSubmitButtonVisible to Form that controls the visibility of the submit button. This prop should have a default value of true to not break any existing components that use Form.
This is probably good for the Form case. I think sometimes an alternative can be to figure out how to pass an element you would otherwise toggle with a boolean prop in as a child or prop and then have the parent control it's visibility by either passing in the button or not. That is sometimes more flexible than a boolean prop - but probably not be worth worrying about in this case (and would be a lot more changes).
@youssef-lr I'm assuming you are also actively working on this - if so, we can add the Internal
label
Should we be showing all possible errors messages from the errors object?
Is there is any discussion I can look at about why we made the switch from an error
key to the errors
object key? As right now, I checked the code for occurrences of the errors
Onyx key, and could not find where we include more than one item in the array (please correct me if I missed something). So I'm not sure yet how we would handle displaying all of the errors because the current format right now only sends out a single error.
There's also a new addition to passing errors from the backend which is errorFields
which should contain any server side errors related to specific inputs. I'm working on including it as well in Form
.
Is there is any discussion I can look at about why we made the switch from an error key to the errors object key?
IIRC this is where we discussed it, not sure if there were other discussions around it though.
As right now, I checked the code for occurrences of the errors Onyx key, and could not find where we include more than one item in the array (please correct me if I missed something). So I'm not sure yet how we would handle displaying all of the errors because the current format right now only sends out a single error.
That may be the case now, but our OfflineWithFeedback component does allow multiple errors to be passed and displayed here. So we should have the same behavior for Forms.
There's also a new addition to passing errors from the backend which is errorFields which should contain any server side errors related to specific inputs. I'm working on including it as well in Form.
👍 IIRC errorFields
was explicitly added for Form errors, so we should support that in Form.
Update: I have a draft PR, should be ready for review today.
Issue updated and PR ready to review! There's one thing I haven't implemented yet which is displaying all of the errors, I think we'll need to check with the design team about how they should look on top of the submit button?
@youssef-lr Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Not overdue.
bump! @marcaaron and @luacmartins! Would love your input on the use of errorFields
in Form
in the PR linked here.
@youssef-lr what exactly did you want input on? Is it whether or not we should use errorFields
in Form? Or how to display those errors, or something else?
@luacmartins sorry I completely missed your comment. The PR basically handles displaying errorFields
that are coming from the backend, which isn't currently supported, but isn't widely used in the backend either.
@youssef-lr I think it would be a good idea to support errorFields
. We always want to show the error in the field that caused it, but in the past the API didn't return the error field, but I think that we should incorporate that going forward.
I'll be updating the PR today and removing WIP
, it looks like we have some more interest in having this implemented.
Totally agree with doing this. A great example of us running into this is here.
Agreed, this is a great one to make sure we get right. Putting this one in WAQ.
@youssef-lr Whoops! This issue is 2 days overdue. Let's get this updated quick!
@youssef-lr Huh... This is 4 days overdue. Who can take care of this?
This has been deployed to production.
Problem
We recently started returning an
errors
object inonyxData
from the API that contain the latest error related to a form submission. The currentForm
component does not take into account the new key and no server error message gets displayed when we submit incorrect data.There are also some cases where we need to hide the submit button but this is currently not possible as it is abstracted away from outside components. Example: when adding a bank account from Plaid, we need to hide the button while Plaid is loading and when the user hasn't selected a Plaid account yet from the picker.
Since there are a few ongoing PRs that depend on the
Form
component, I figured it might be a good idea to create a separate PR for this and have the PRs merge with main.cc @luacmartins @marcaaron
Solution
getErrorMessage
function toForm
that extracts the latest error message from theerrors
object. For API calls that still return anerror
key, this should still work as the function below checks for both keys.Rename
setErrorMessage
inactions/FormActions.js
tosetErrors
.Add an optional prop
isSubmitButtonVisible
toForm
that controls the visibility of the submit button. This prop should have a default value oftrue
to not break any existing components that useForm
.Handle field-specific errors coming from the backend and display them on the inputs that need attention.
If there are any
errorFields
, display the errors on the input and display thefixTheErrors
.