I am encountering a strange bug using JQuery Draggable and Sortable plugins.
I have a list of draggable objects that can be added to a sortable container.
The function of the page is to be able to add content (draggables) to a page (sortable) and being able to sort it afterwards. I can add many types of contents such as texts, graphs, tables and files (for example images)...
When he drops the image object into the sortable container, I want the user to select a file from his computer to upload. So I simulate a "click" on an input file at the end of the dropping (as the draggable and sortable are connected, this happens in the "update" event of the sortable).
But I don't know why, the click event of the input file does get triggered (I checked with console.log()
) but the "select file" window is never opened.
If I type my $('#upl input').click();
in the firebug console, it works... if I fire the click event in a third link, it works. But when the "click" is in the update event of the sortable container, the window just won't show up. I even tried delaying the click with a setTimeOut to wait till the update event is over, but still, the click event gets fired but no window...
Has anybody ever encountered this problem ?
Here is a simplification of my problem on jsfiddle. https://jsfiddle.net/jp51cadt/3/ you can drop the "Image" into the square. It fires the click on the lower input but the upload window doesn't show up.
function updateSortable(event, $ui) {
$('#upl input').on("click", function() {
alert("this works");
});
$('#upl input').click(); // not this
}
I add the alert to show that the click is fired...