react-final-form-arrays
react-final-form-arrays copied to clipboard
`fields.remove` call with array of file inputs always removes last input in array, regardless of index argument
Are you submitting a bug report or a feature request?
A bug report
What is the current behavior?
Input arrays don't work with file inputs (<input type="file" />
) as expected. When clicking any of the remove buttons in the supplied sandbox, the last entry in the list of inputs is removed, not the one selected. (the fields.remove
function always removes the last input, regardless of the index argument). When substituting text input fields instead of file uploads, it works as expected. (see second sandbox link)
What is the expected behavior?
The fields.remove
function should remove the input at the index it was passed, not the last one.
Sandbox Link
File inputs: https://codesandbox.io/s/silly-stonebraker-vyi6l Text inputs: https://codesandbox.io/s/jovial-kalam-8esq7
What's your environment?
"final-form": "4.16.1"
"final-form-arrays": "1.1.2"
"react": "16.8.6"
"react-dom": "16.8.6"
"react-final-form": "6.3.0"
"react-final-form-arrays": "3.1.0"
Other information
None.
This is the same for <input type="checkbox" />
The same problem, maybe anybody resolves this?
Hi @lShinal @rickysullivan @GyrosOfWar I think it's not a bug, I just checked the source code,
remove: (index: number) => FieldValue .
the function of remove accept a para "index", not the value in the array. We can use it like this below:
if (value) fields.push(option);
else fields.remove(fields.value.indexOf(option));
same trouble issue "react-final-form": "^6.3.0", "react-final-form-arrays": "^3.1.1",
Anyone solved this?
@litao8976 why you do `
if (value) fields.push(option);
else fields.remove(fields.value.indexOf(option));
` why push here?
@GyrosOfWar , how do you solved this?