Using PF10 (in a JoinFaces project), I'd like the Upload File dialog for choosing a file to show up when the page loads (i.e., without waiting for the user to click on the Choose button of <p:fileUpload/>). How can I do that?
            Asked
            
        
        
            Active
            
        
            Viewed 331 times
        
    2
            
            
         
    
    
        mossaab
        
- 1,812
- 4
- 23
- 44
1 Answers
2
            You could use client side API show() function for this. But it seems more and more browsers are blocking triggering a click by script on an input type="file". See https://github.com/primefaces/primefaces/issues/7772
You could take your chances and try to hijack a mouse move event to trigger a click on the upload input, which is answered on this question: In JavaScript can I make a "click" event fire programmatically for a file input element? But I don't really like that hack.
 
    
    
        Jasper de Vries
        
- 19,370
- 6
- 64
- 102
- 
                    I've just tried the following `````` Nothing happens, but the console shows "File chooser dialog can only be shown with a user activation." I guess this means this is not possible? – mossaab Aug 31 '21 at 14:08
- 
                    @mossaab what browser are you using? He mentioned above Firefox seems to have an issue but Chrome does not. – Melloware Aug 31 '21 at 20:22
- 
                    @Melloware I tried on Chrome Version 92.0.4515.159. – mossaab Sep 01 '21 at 21:07
- 
                    Thanks @JasperdeVries! I'm accepting "not possible" as an answer. – mossaab Sep 02 '21 at 14:28