React-final-form: resetFieldState breaking hard on not-yet mounted fields

Created on 11 Sep 2019  路  6Comments  路  Source: final-form/react-final-form

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

Getting the following error when conditionally rendering and resetting a field (subcategory) based on another field (category)

Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at getValidators (final-form.es.js:568)
    at runFieldLevelValidation (final-form.es.js:581)

What is the expected behavior?

// Resets the subcategory to undefined
form.change("subcategory", undefined);
// Resets the field state
form.resetFieldState("subcategory");

to work whether or not the field subcategory is mounted or not.

Sandbox Link

https://codesandbox.io/s/react-final-form-simple-example-7jt63

What's your environment?

react 16.9.0
final-form 4.18.5
react-final-form 6.3.0

Other information

The expectations:

  • show subcategory field only after the user make a selection on category field
  • clearing any selections in subcategory field when the user change category
  • resetting the state of subcategory field (to hide any validation errors or messages)

Most helpful comment

+1 resetFieldState not working for me neither on a conditional field.

My use case is that when a "parent" field value changes I want to reset the state of the depending conditional fields like they had never been interacted with.
In this case the conditional field might have never been or no longer be rendered; but it has been registered and so I would expect Final Form to imperatively perform operations on it.

This issue has been opened since Sept would be great to get a comment from maintainers so we know what we can expect.

All 6 comments

Any progress on this ? The issue happened when we programatically resetting the field using hooks regardless if the field is mounted or not

Any advance? Please, a possible solution to this problem is necessary :( .

I am having this issue when trying to reset field too

(using react-admin)

resetFieldState still doesn't work

+1 resetFieldState not working for me neither on a conditional field.

My use case is that when a "parent" field value changes I want to reset the state of the depending conditional fields like they had never been interacted with.
In this case the conditional field might have never been or no longer be rendered; but it has been registered and so I would expect Final Form to imperatively perform operations on it.

This issue has been opened since Sept would be great to get a comment from maintainers so we know what we can expect.

It seems like something similar happens with FieldArrays

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Soundvessel picture Soundvessel  路  4Comments

Noisycall picture Noisycall  路  4Comments

LucienBouletRoblin picture LucienBouletRoblin  路  3Comments

CodeWithOz picture CodeWithOz  路  4Comments

jkantr picture jkantr  路  4Comments