-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
formatOnBlur: Also run on submit #470
Comments
You could always do the formatting in your submit function before sending it off to the server. Something like: function onSubmit(values) {
stringKeys.forEach(key => values[key] = format(values[key]))
ajax.send(values)
} <Form onSubmit={onSubmit}/> |
I hoped to avoid having to put code for this in every single submit function ;) Also, this wouldn't trigger validation errors for fields that cannot be empty or have a minimum length (which I want to apply on the trimmed value of course). |
You make good points. |
You could use jQuery! 🤣 I'm joking... Because React Final Form is just responding to the events the browser gives it, this is going to require more complex communication between the Final Form engine and the fields. |
Published fix in |
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. |
1 similar comment
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. |
I'm using
formatOnBlur
to trim strings. This works fine, but if someone submits by pressing the enter key without leaving the field first, then no blur event happens and the string is submitted as-is without the formatter code running.Or is there a better way to trim all strings before submission? format+formatOnBlur is pretty convenient because we're using a custom Field wrapper component that always sets it for string fields.
The text was updated successfully, but these errors were encountered: