Hi all,
I am facing a difficulty where I need to prevent the component from opening the file browser directly upon clicking
or
prevent the upload of the file to the server when the user tries to drag and drop the file to the widget by prompting a confirmation message to the user.
For case 1 (click):
When the user clicks on the widget, a confirmation message will be prompted and the file browser will only be opened when the user clicked Ok, else nothing will happen.
For case 2 (drag & drop):
When the user drags and drops the file(s) onto the widget, a confirmation message will be prompted and the file(s) will only be loaded to the server for processing when the user clicked Ok, else nothing will happen.
I've looked into the forge and only can find uploaded/uploadstarted event where my case should be triggered even before they select the file.
What I have also tried is to put a button where the widget is hidden, and when the button is clicked, a confirm() JS will be triggered and getelementbyId().click() will click on the widget but it doesn't work (even if it works, it will not work for drag & drop feature).
If anyone has any idea(s), feel free to provide your feedback as every feedback is welcomed. Thanks!
Kenny
To achieve the desired behavior of prompting a confirmation message before allowing file selection via clicking or drag-and-drop, you can use a combination of JavaScript and CSS in your OutSystems application. Below are the steps to implement the functionality:
Step 1: Create a Custom Button Create a custom button that will be visible to the user instead of the default file input widget. The custom button will serve as a trigger to open the file browser or handle the drag-and-drop event.
Step 2: Hide the Default File Input Hide the default file input widget using CSS so that users only interact with the custom button.
Step 3: Implement Confirmation Logic When the custom button is clicked or when the user drags and drops a file onto the widget area, use JavaScript to prompt the confirmation message. If the user confirms, programmatically trigger the click event on the hidden file input to open the file browser or proceed with file upload.
Here's an example of how you can achieve this in OutSystems:
Create a custom button using a regular button or link widget in your OutSystems screen. Style the button to make it visually appealing and recognizable as a file upload trigger.
Hide the default file input widget using CSS. Add a CSS class (e.g., "hidden-file-input") to the file input widget, and define the CSS class to hide it:
css
.hidden-file-input { display: none;}
JavaScript code:
javascript
function confirmFileSelection() { if (confirm("Do you want to select/upload the file?")) { // User confirmed, trigger click event on the hidden file input document.getElementById("hiddenFileInput").click(); } else {
// User canceled, do nothing
}
function handleDragOver(event) {
event.preventDefault();}
function handleDrop(event) {
event.preventDefault();
confirmFileSelection();}
document.addEventListener("DOMContentLoaded", function () { document
.getElementById("customButton")
.addEventListener("click", confirmFileSelection);
var widgetArea = document.getElementById("widgetArea"); widgetArea.addEventListener("dragover", handleDragOver);
widgetArea.addEventListener("drop", handleDrop);});
In the OutSystems screen, apply the "hidden-file-input" CSS class to the default file input widget and set its ID to "hiddenFileInput."
In the custom button's onclick event, call the JavaScript function "confirmFileSelection()" to prompt the confirmation message and trigger the file input click event.
In the widget area (where drag-and-drop is allowed), apply the "handleDragOver" and "handleDrop" JavaScript functions to the corresponding events.
By following these steps, you should be able to prompt a confirmation message before allowing the file selection via clicking or drag-and-drop, as per your requirements.
Hi Mr. Shravanth,
Thanks for the input, but have you tried out the forge? Or do you have any samples/oml to achieve that? I'm not trying to offend you, but your recent posts look like "ChatGPT-Generated" to me. But nevertheless, really appreciate your effort in looking into this :)
Regards,
Hello Yung Shin,
Thank you for your question.
The ReactFilePondUpload component does not support the scenario you mentioned.
The inbuilt OutSystems file upload component does not immediately upload files. So using that will get you most of the way toward your requirements.
I hope this helps.
Kind regards,
Stuart
Thanks Stuart,
I'll try to explore the alternative solution as I have yet to find a forge that supports the case that I've mentioned. Although the inbuilt Outsystems file upload does not immediately upload files (works the same when we disable the IsAutoUpload on reactfilepond (I guess)), it does not support multiple files or drag and drop feature and needs to customize as well just to cater for prompting confirmation message before opening the file browser. But thanks again, and have a great day ahead!