Conditional disable
how can I disable a form fields based on the value selected in another form field?
5 Replies
genetic-orange•14mo ago
Have a look at Linked Fields:
https://github.com/TanStack/form/blob/main/docs/framework/react/guides/linked-fields.md
flat-fuchsiaOP•14mo 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
genetic-orange•14mo 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.flat-fuchsiaOP•14mo ago
I see, thanks, i'm gonna give it a look
genetic-orange•14mo 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