Skip to content

Commit

Permalink
fix: issue collective#73
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarde committed Aug 5, 2024
1 parent d7221de commit f4e6d98
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/Widget/FileWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ const FileWidget = (props) => {
}
};
reader.readAsDataURL(files[0]);

/* add dummy file to input element,
to make sure the browsers form validation
recognizes this field as filled
*/
let inputEl = document.getElementById(`field-${id}`);
const myFile = new File([], file.name, {
type: 'text/plain',
lastModified: new Date(),
});
const dataTransfer = new DataTransfer();
dataTransfer.items.add(myFile);
inputEl.files = dataTransfer.files;
// help Safari out by setting the data-file attribute
if (inputEl.webkitEntries.length) {
inputEl.dataset.file = `${dataTransfer.files[0].name}`;
}
};

let attributes = {};
Expand Down

0 comments on commit f4e6d98

Please sign in to comment.