Files
solidlime-Comfyui-Random_Im…/web/random_image_picker.js
T
solidlime f453a4fe47 Improve user guidance for file path input
Changes:
- Added tooltips to all input parameters explaining their purpose
- Enhanced alert dialog with detailed instructions and examples
- Shows current default path in the alert
- Better formatting for multi-line instructions
- Added dynamicPrompts: false to image input for better UX

Note: Browser security prevents automatic full path detection.
Users need to manually enter the complete file path after using the file picker.
2026-01-07 21:12:14 +09:00

55 lines
2.5 KiB
JavaScript

import { app } from "../../scripts/app.js";
app.registerExtension({
name: "Comfy.RandomImagePicker",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "RandomImagePicker") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
const node = this;
// Add browse button
node.addWidget("button", "📁 Choose File", null, () => {
const input = document.createElement("input");
input.type = "file";
input.accept = "image/png,image/jpeg,image/jpg,image/webp,image/bmp,image/gif";
input.onchange = (e) => {
if (e.target.files && e.target.files[0]) {
const file = e.target.files[0];
const imageWidget = node.widgets.find(w => w.name === "image");
if (imageWidget) {
// Show selected file name
const fileName = file.name;
console.log("Selected file:", fileName);
// Show dialog with instructions
const currentPath = imageWidget.value || "";
const dialogText = `File selected: ${fileName}\n\n` +
`⚠️ IMPORTANT:\n` +
`Due to browser security, the full path cannot be automatically detected.\n\n` +
`Please copy and paste the FULL PATH to this file in the 'image' field above.\n\n` +
`Example:\n` +
`D:\\Images\\${fileName}\n` +
`or\n` +
`C:\\Users\\YourName\\Pictures\\${fileName}\n\n` +
`Current default: ${currentPath || '(not set)'}`;
alert(dialogText);
}
}
};
input.click();
});
return result;
};
}
}
});