You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a form with dynamic part, containing a group of fields, that can be added or removed
For each a group i have field1 and field2
When i fill field1, i want to fetch data from my apy (with TSQuery) based on the given value.
Then with the API answer, i want to update field2
I have tried multiple things :
validator.onChangeAsync
validator.onChangeListenTo
listeners.onChange
useStore
form.Subscribe
I can't figure if using one these methods is the right way, right now the only solution i found is useState and useEffect causing the whole part to re-render loosing the advantages of TanStack Form
Here is what it looks like :
constDynamicPart=withForm({
...formOpts,props: {index: 0,},render: ({ form, index })=>{const{ data }=useGetData(// useQuery hunder the hood, generated by [Kubb](https://kubb.dev/plugins/plugin-react-query/){value: form.getFieldValue(`attribute[${index}].value`),},{query: {queryKey: [form.getFieldValue(`attribute[${index}].value`)],enabled: Boolean(form.getFieldValue(`attribute[${index}].value`)),},},);return(<div><form.AppFieldname={`attribute[${index}].value`}validators={{onChangeAsync: async()=>{form.setFieldValue(`attribute[${index}].name`,data.name);},onChangeAsyncDebounceMs: 500,}}children={(field)=><field.TextFieldlabel={`Value ${index+1}:`}/>}/><form.AppFieldname={`attribute[${index}].name`}children={(field)=><field.TextFieldlabel="Name:"required={true}/>}/></div>);},});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Here is my problem (code below):
field1
andfield2
field1
, i want to fetch data from my apy (with TSQuery) based on the given value.field2
I have tried multiple things :
validator.onChangeAsync
validator.onChangeListenTo
listeners.onChange
useStore
form.Subscribe
I can't figure if using one these methods is the right way, right now the only solution i found is useState and useEffect causing the whole part to re-render loosing the advantages of TanStack Form
Here is what it looks like :
Beta Was this translation helpful? Give feedback.
All reactions