Conditional disable
how can I disable a form fields based on the value selected in another form field?
5 Replies
secure-lavender•17mo ago
Have a look at Linked Fields:
https://github.com/TanStack/form/blob/main/docs/framework/react/guides/linked-fields.md
harsh-harlequinOP•17mo ago
I already checked it out but didn't quite understand how to set the disable, I tried something like this:
but it doesn't look reactive
secure-lavender•17mo ago
@Ladvace I guess this is more for validation logic.
I did figure it out. Use
form.Subscribe
For example I did implement this on the simple example:
So, it is similar to how we would get the canSubmit and isSubmitting for the Button but instead we select the state.value we need.harsh-harlequinOP•17mo ago
I see, thanks, i'm gonna give it a look
correct-apricot•17mo ago
Reactivity can be mainly achieved in two ways, with form.useStore or form.Subscribe (docs)
Susbscribe works fine but in your case I'd go with
useStore to avoid that extra level of nesting
Basic Concepts and Terminology | TanStack Form React Docs
This page introduces the basic concepts and terminology used in the @tanstack/react-form library. Familiarizing yourself with these concepts will help you better understand and work with the library.
Form Options