-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
v3: no longer possible to know whether a form has been submitted #889
Comments
ok i found a fix: on the ValidatedForm there is state.validate which is true when the form has been submitted but failed the validation. While the name is maybe a bit missleading, this is exactly what i need i prepared a small PR #890 |
Hi @macrozone. I'll comment on both your request and #890 here. There is no way to know whether the form was submitted in general. I see that you found the EDIT: Also, the title says no longer - I'm pretty sure this information was never part of the API - could you explain what you meant? |
What do you suggest as property? It's meaning i "form has been tried to be submitted, but validation failed or validation is not yet done". Something like a "submitCount" could maybe also be used for that, paired with "submitSuccessCount" to highlight that "submitCount" also counts unsuccessful submits (where validation failed)
previously, you could know whether the form was submitted, because the fields would receive |
Let's start with this flag meaning. You've said, "form has been tried to be submitted, but validation failed or validation is not yet done". I fully agree with the first part ("form has been tried to be submitted") and not with the rest of it. I believe you assume that all forms are closed or reset after submission - then it's true but it's not always the case. Also, I think that I have also thought about a counter instead of a flag, but I see no use case for it. And I find the "counter of unsuccessful submits" quite artificial. And about the workaround in v2. Now I get it. And I agree it was not clear at all. Thanks for the explaination. |
In our case we have a submitting state value in the parent component that gets toggled in the onSubmit handler before and after handling the submit.. Something like: submit = async (userInput: any = {}) => {
const { submitting } = this.state;
if (!submitting) {
this.setState({ submitting: true });
try {
await this.props.onSubmit(userInput);
this.setState({ submitting: false });
} catch (error) {
this.setState({ submitting: false });
}
}
} |
@radekmie that does not work, as this submitting property is never true when validation is sync. |
@macrozone: based on the signature of the |
we used submitting in v2, that was true for a brief moment (tick) even when the form was submitted, but before validation. in @hmvp 's implementation submitting will also never be true for a sync onSubmit function. Its probably not good to rely on something that is true for a short time, its better to have something persistent, like a counter or so |
@macrozone: will you continue working on #890? If not, please do close it - we'll pick it up from here. |
@radekmie currently i solved in userspace by extending ValidedForm:
this works, but i for my case its enough to know whether submitting has been tried at least once, in principle thats the same condition which makes |
Have you read #889 (comment)? I suggested a |
submitted is wrong i think. I would assume that "submitted" would only be true if But i need a flag that is true when the form has been tried to be submitted, but independent whether validation or onSubmit was successful. |
I understand. As I already wrote:
If you have a suggestion, then let me know, |
alright, that is also valid point of view i think. So let's go with that, i'll update my pr then |
@macrozone: will you continue this PR? If not, please do close it and we'll take it from here. |
@radekmie i'll do it now |
we validate form fields on the fly, that means we show an error when a field has been filled and somethign is wrong
we achieved this with using
validate="onChange"
, but only show an error if the field was either touched or changed.We also showed all errors when the user tried to submit the form.
we set touched=true when either the field was blurred or when the form was "submitting".
Problem is now that submitting is never
true
, so that does not work anymore (we also needed touseForm().submitting
)is there a way to find out if the form has ever been submitted?
The text was updated successfully, but these errors were encountered: