Skip to content
Source
Sign inSign up
TanStack/form

New API - resetField('fieldName') #1177

Send to my agent
Closedcrutchcorn(GitHub profile, opens in a new tab) opened this issue 6 comments

Discussed in https://github.com/TanStack/form/discussions/1159

Originally posted by **wilson12365** February 19, 2025 right now the only way to handle reset a field based on other actions of the form is the following
listeners={{
  onChange: ({value}) => {
    const defaultMeta = {
      isValidating: false,
      isTouched: false,
      isBlurred: false,
      isDirty: false,
      errorMap: {}
    }

    if (value === ‘personal’) {
      setFieldValue(‘businessName’, ‘’)
      setFieldValue(‘businessLabel’, ‘’)
      setFieldMeta(’businessName’, defaultMeta)
      setFieldMeta(’businessLabel’, defaultMeta)
    }
}}

@crutchcorn has suggested to add resetField('fieldName')

  1. crutchcorn(GitHub profile, opens in a new tab) added labelstype: enhancement

  2. crutchcorn(GitHub profile, opens in a new tab) added labelsgood first issue

  3. maybe an updateFieldMeta function, setFieldMetaAndValue function and a defaultMeta export would make this a lot more ergonomic but still flexible

  4. @crutchcorn, I could pick this up if you could give a little more detail. I'm back from holidays so I should have some time around the weekend to open a pr

    So this is form.resetField() and should revert to the default field value and cleared meta?

  5. @blipk what about my https://github.com/TanStack/form/pull/1125 pr, would that help with the updateFieldMeta part?

  6. @selah-EN-HC-glitch I just released it to main, so update your packages then you can use form.resetField('firstName')

  7. Thank you for adding this! For nested fields, this only works on the leaves , and not on the parent field. Is there a solution that propagates the reset from the parent field to all of its nested fields?

Sign in to join this conversation.