T
TanStack•5mo ago
fascinating-indigo

How to reset the value of an object field in an array

hi everyone. is there a way to reset manually a value in an array field?
<td>
<form.Field
name={`lines[${i}].building_product_group`}
>
{(subfield) => (
<Select
...
onChange={(e) => {
subfield().handleChange(
e.currentTarget.value,
);
// <--- How can i reset building_product_type ?
}}
/>
)}
</form.Field>
</td>
<td>
<form.Field
name={`lines[${i}].building_product_type`}
>
{(subfield) => (
<Select
options={
// <--- options depends on building_product_group
}
...
/>
)}
</form.Field>
</td>
<td>
<form.Field
name={`lines[${i}].building_product_group`}
>
{(subfield) => (
<Select
...
onChange={(e) => {
subfield().handleChange(
e.currentTarget.value,
);
// <--- How can i reset building_product_type ?
}}
/>
)}
</form.Field>
</td>
<td>
<form.Field
name={`lines[${i}].building_product_type`}
>
{(subfield) => (
<Select
options={
// <--- options depends on building_product_group
}
...
/>
)}
</form.Field>
</td>
8 Replies
xenial-black
xenial-black•5mo ago
you may be looking for listeners it lets you have side effects for other fields if your field triggers the event
fascinating-indigo
fascinating-indigoOP•5mo ago
ooouh nice, i wasnt aware of the existence of listeners, but it sounds like what i need !!
xenial-black
xenial-black•5mo ago
I'll fetch the docs link for you.
fascinating-indigo
fascinating-indigoOP•5mo ago
hopefully it exists for solid form 😅
xenial-black
xenial-black•5mo ago
I don't think so, but it should be fairly easy to adapt. The fieldApi methods should be the same https://tanstack.com/form/latest/docs/framework/react/guides/listeners here's the react version for comparison
Side effects for event triggers | TanStack Form React Docs
For situations where you want to "affect" or "react" to triggers, there's the listener API. For example, if you, as the developer, want to reset a form field as a result of another field changing, you...
fascinating-indigo
fascinating-indigoOP•5mo ago
thank you!
xenial-black
xenial-black•5mo ago
I should clarify, you definitely 100% can do it in solid, but there's no docs explicitly for it
fascinating-indigo
fascinating-indigoOP•5mo ago
yeah no doc is fine ;D i can adapt it to solid

Did you find this page helpful?