Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API - resetField('fieldName') #1177

Open
crutchcorn opened this issue Feb 25, 2025 · 3 comments
Open

New API - resetField('fieldName') #1177

crutchcorn opened this issue Feb 25, 2025 · 3 comments
Labels

Comments

@crutchcorn
Copy link
Member

Discussed in #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')

@blipk
Copy link

blipk commented Feb 26, 2025

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

@harry-whorlow
Copy link
Contributor

harry-whorlow commented Mar 3, 2025

@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?

@harry-whorlow
Copy link
Contributor

harry-whorlow commented Mar 4, 2025

@blipk what about my #1125 pr, would that help with the updateFieldMeta part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants