final-form icon indicating copy to clipboard operation
final-form copied to clipboard

Set blur, focus and change in InternalFieldState when registerField is called.

Open huan086 opened this issue 5 years ago • 2 comments

If mutator creates a new field in MutableState for keeping the field state of a renamed field, set the blur, focus and change function of InternalFieldState when registerField is called.

This is needed by react-final-form-array because of this sequence of events as shown in https://github.com/final-form/final-form-arrays/issues/58

  • FieldArray registers foo
  • Field registers foo[0].a
  • Field registers foo[1].b
  • call remove mutator to remove foo[0]
  • in order to keep field states (touched, visited etc), remove mutator copies the field foo[1].b to foo[0].b. Note that there isn't any input fields subscribed to foo[0].b
  • FieldArray unmounts Field foo[1].b
  • Field foo[0].a gets re-rendered, runs the useEffect clean up on foo[0].a and registers foo[0].b

Before this pull request, blur, focus and change would be undefined because the mutator is not able to set these functions because mutators do not have access to form. The Field foo[0].b would then error out and won't respond to input

This pull request ensures blur, focus and change are set when registerField is called.

Fixes final-form/react-final-form-arrays#127

huan086 avatar Nov 12 '20 14:11 huan086

Codecov Report

Merging #393 (a0b892e) into master (9c732e2) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #393   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines          591       591           
  Branches       124       127    +3     
=========================================
  Hits           591       591           
Impacted Files Coverage Δ
src/FinalForm.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9c732e2...33e551f. Read the comment docs.

codecov[bot] avatar Nov 12 '20 15:11 codecov[bot]

Any eta for when this will be merged? Dragging and dropping with nested field arrays is rather broken right now. @erikras

johancallvik avatar Dec 11 '20 08:12 johancallvik