Skip to content

Commit b80a5f4

Browse files
authored
fix: dynamically added filefields (#846)
1 parent f1322f4 commit b80a5f4

File tree

1 file changed

+20
-9
lines changed
  • src/unfold/static/unfold/js

1 file changed

+20
-9
lines changed

src/unfold/static/unfold/js/app.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,26 @@ const dateTimeShortcutsOverlay = () => {
135135
* File upload path
136136
*************************************************************/
137137
const fileInputUpdatePath = () => {
138-
Array.from(document.querySelectorAll("input[type=file]")).forEach((input) => {
139-
input.addEventListener("change", (e) => {
140-
const parts = e.target.value.split("\\");
141-
const placeholder =
142-
input.parentNode.parentNode.parentNode.querySelector(
143-
"input[type=text]"
144-
);
145-
placeholder.setAttribute("value", parts[parts.length - 1]);
146-
});
138+
const observer = new MutationObserver((mutations) => {
139+
for (const mutation of mutations) {
140+
if (mutation.type === "childList") {
141+
for (const input of document.querySelectorAll("input[type=file]")) {
142+
input.addEventListener("change", (e) => {
143+
const parts = e.target.value.split("\\");
144+
const placeholder =
145+
input.parentNode.parentNode.parentNode.querySelector(
146+
"input[type=text]"
147+
);
148+
placeholder.setAttribute("value", parts[parts.length - 1]);
149+
});
150+
}
151+
}
152+
}
153+
});
154+
155+
observer.observe(document.body, {
156+
childList: true,
157+
subtree: true,
147158
});
148159
};
149160

0 commit comments

Comments
 (0)