-
-
Couldn't load subscription status.
- Fork 61
Open
Description
IS
If you reset a file input by setting its value to "" and dispatching an input event, modular-forms keeps the previously selected file in the form state.
SHOULD
Resetting the file input value with the mentioned logic, should result in the value being cleared in the form state.
Extra information
The reason for this happening is in the following lines:
-
files[0]is undefined for an empty file input:? files[0] -
since the value from
getElementInputis undefined, this is gonna fallback toprevValue:inputValue ?? prevValue
Workaround
Add the following transform to your file fields.
export const toOptionalFile = (value: any, evt: FieldEvent) => {
const input = evt.target as HTMLInputElement;
if (!input.files?.length) return;
return value
}Metadata
Metadata
Assignees
Labels
No labels