How to fields disable when form submitting?
This is my reusable code and i try to add disable when submitting but it is not working. It update as true when submit click but not update again to false when validation error or submit finished.
I used this code to check it -
{"Subminiting?:" + (field.form.state.isSubmitting === true ? "Yes" : "No")}
12 Replies
absent-sapphire•3w ago
This is my reusable codeAre you using form composition, or are you passing this in the callback?
foreign-sapphire•3w ago
isSubmitting flag
absent-sapphire•3w ago
the flag's correct, but it's likely not reactive on its own. You'll want to use one of the two ways to get a reactive value
other-emeraldOP•3w ago
This is form component for reuse.
absent-sapphire•3w ago
this feels like you want form composition instead. https://tanstack.com/form/latest/docs/framework/react/guides/form-composition
Form Composition | TanStack Form React Docs
A common criticism of TanStack Form is its verbosity out-of-the-box. While this can be useful for educational purposes helping enforce understanding our APIs it's not ideal in production use cases. As...
other-emeraldOP•3w ago
I use that form compoent and in between <Form></Form> I use FeildInput Component. I can not add full code to this becuase it ask to money.
This renderComponent is above first code and it is inside this
const renderComponent = (field: any) => ( ABOVE CODE FIST CODE WHEN ASK QUESTION). Is this wrong?absent-sapphire•3w ago
it's not type safe, so I'll recommend the docs I sent.
Anyways, your forum post's about the
isSubmitting part, so that can be solved by the comment I sent here:
You said that it worked from false -> true, but not true -> false. That was a coincidence. It actually rerendered because the field has gone from isTouched: false -> isTouched: trueother-emeraldOP•3w ago
Yes, it go to isTouched: false -> isTouched: true. is it related to isSubmitting and not to update?
absent-sapphire•3w ago
isSubmitting does not cause rerenders on its own. You need to subscribe to it.
It would look something like:
other-emeraldOP•2w ago
ok i will check it
thank you very much
Why this code not work?
I always get false for
{"isSubmitting? " + isSubmitting} but form is submitedabsent-sapphire•2w ago
isSubmitting - Is the form currently in the process of submitting
isSubmitted - The form has successfully submitted
other-emeraldOP•2w ago
Yes, i need to disable input field while submiting, but above code not work
is that because i used
const field = useFieldContext(); ?
I mean during the form submitting progress, text field not disabled. Always show false even submitting process in {"isSubmitting? " + isSubmitting}.
I found the error, field.form.store.state.isSubmitting update quickly but values will delay. I do not know why.
When use {console.log(field.form.store.state.isSubmitting)} console see false true false quickly but values print in delay after 10000.
Why isSubmitting is update quickly? isSubmitting should true until 10000 delay.
I found the solution it should be async delay. 🥹