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 setting canSubmit to false in the defaultState option. Then, by checking if both canSubmit and isSubmitting 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 to defaultState. A simple example is as follows:
const form = useForm({
defaultValues: {
firstName: '',
lastName: '',
},
defaultState: {
canSubmit: false,
},
});
console.log(form.state.canSubmit); // Evaluates to true
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-vzvauf?file=src%2Findex.tsx
Steps to reproduce
- Create a form object using the
useForm hook with defaultState: { canSubmit: false } in the props.
- Evaluate the resulting value of
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
- OS: Windows
- Browser: Chrome
- Version: 128
TanStack Form adapter
react-form
TanStack Form version
0.32.0
TypeScript version
No response
Additional context
No response
Describe the bug
I'm trying to create a read only version of a form in React. react-hook-form has the
disabledprop 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 settingcanSubmittofalsein thedefaultStateoption. Then, by checking if bothcanSubmitandisSubmittingare 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
canSubmitis 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
useFormhook withdefaultState: { canSubmit: false }in the props.form.state.canSubmitExpected behavior
By submitting
canSubmit: falsein 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