-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
canSubmit is not set in state when provided to defaultState prop at form initialization #944
Comments
I tried the exact same thing. @Balastrong answered the following in the Discord-Channel:
|
Thanks for the clarification, knowing that we shouldn't touch it is useful information. In that case I hope the docs can be updated to reflect this. Currently it does list defaultState as an option here without providing information that it should not be used. |
To be fair, the docs you're pointing to are actually autogenerated and only really meant for deep dives and assistance in reading the codebase. What guidance are you generally looking for here? |
I'm not sure I understand your question. In my experience, the API exposed by a library is exposed specifically because it is made available to a user. The same goes for documentation for said API. When something is meant for development or testing, I see it is generally left out of the documentation, marked private, or is clearly indicated to be for internal use only (for example a field called Regardless, I totally understand that things like this are inevitable for libraries that haven't matured yet. When I installed this library, I expected there to be peculiarities that hadn't been fleshed out due to it being a pre-1.0 release. Still, I do think it can be helpful to mark those fields as internal one way or the other to prevent users like me making bug reports about parts of the API that are supposed to be internal and are thus not behaving as expected. As for the specific reason this issue came up: I'm making a CRUD application and I hoped to populate the fields with the Form API in a read-only state. That way I could use the same layout for not only the C and U, but also the R. As I wrote in the original post, react-hook-form has a |
Describe the bug
I'm trying to create a read only version of a form in React. react-hook-form has the
disabled
prop in the UseForm prop which propagates to all fields and I hope a similar feature could be added to Tanstack form. I wanted to emulate a read only form by settingcanSubmit
tofalse
in thedefaultState
option. Then, by checking if bothcanSubmit
andisSubmitting
are false, the form must be read only. I hope my understanding about how those two fields work is correct.However, I found out that the value for
canSubmit
is ignored when provided todefaultState
. A simple example is as follows:Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-vzvauf?file=src%2Findex.tsx
Steps to reproduce
useForm
hook withdefaultState: { canSubmit: false }
in the props.form.state.canSubmit
Expected behavior
By submitting
canSubmit: false
in the defaultState, I expect the state after initialization to contain a false value for this property. The value is true however, which is not expected. If this is intentional, it is very counter-intuitive, but if this is unintentional then I think it needs fixing.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
TanStack Form adapter
react-form
TanStack Form version
0.32.0
TypeScript version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: