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

focus last after fields.push() not possible, because no possibility to focus on callback

Open andylacko opened this issue 6 years ago • 4 comments

Hello, I have 1 suggestion, when I push value, can't focus new element, because it is not created yet

                 fields.push({id: '', name: '', lastName: ''})
                 setTimeout(()=>{
                   form.focus(`persons[${fields.value.length}].id`)
                 },200)

this is how it works now, but obviously, its really bad solution, if fields.push had a callback, it would be nice

just wondering, why fields.push acts like async?

andylacko avatar Feb 22 '19 15:02 andylacko

I stumbled upon the same issue. Is there any update on how to focus the new element?

Chrisdo82 avatar Feb 27 '19 08:02 Chrisdo82

I have the same issue Could you pl help?

InnaKutsik avatar Mar 25 '19 14:03 InnaKutsik

This can be solved by creating your own push mutator with a callback. Push mutator is pretty simple if you look into the source code

Juansasa avatar May 06 '19 07:05 Juansasa

@Juansasa do you have any examples of this? I can't see how a callback will help in this situation as we need the callback to be triggered once the field has been mounted/appended to DOM, not just directly after pushing to the array.

p12y avatar May 31 '21 03:05 p12y