form icon indicating copy to clipboard operation
form copied to clipboard

New API - resetField('fieldName')

Open crutchcorn opened this issue 8 months ago • 5 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')

crutchcorn avatar Feb 25 '25 06:02 crutchcorn