Skip to content

Instantly share code, notes, and snippets.

@whamtet
Created January 28, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whamtet/f088248ae50010f2e218f385178d02a9 to your computer and use it in GitHub Desktop.
Save whamtet/f088248ae50010f2e218f385178d02a9 to your computer and use it in GitHub Desktop.
Keep selected files
var files;
htmx.defineExtension('file', {
onEvent: function(type, evt) {
if (type === 'htmx:beforeSwap') {
files = htmx.findAll(evt.target, 'input[type="file"]');
}
if (type === 'htmx:afterSwap') {
for (file of files) {
const target = document.getElementsByClassName(file.className)[0];
target.replaceWith(file);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment