Handling / clearing value of file input

I have a file input and I’d like to allow the user to “clear” the value. I’m using a field on my model to track whether the file has been selected and I can modify that value to create the appearance that it’s been cleared, but then the user is unable to select the same file again because the DOM element input still contains that value and my onChange event won’t fire.

Most inputs I can automatically set the value for, but afaik the protected path of the file isn’t something I can set with a value attribute. Do I have to change something else about the element so it will re-render and “forget” the value?

Thanks for any help

Hi,

I suppose that using a Html.Keyed node and changing the identifier for your input should work (you can increment a number or maybe use the filename, and the identifier change will force the Elm virtual DOM to re-create the element ).

This is the same technique as the one used for defaultValue and input fields (see this example from zwilias taken from here).

1 Like

Html.Keyed worked perfectly, thank you!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.