Ouerghi Yassine
Ouerghi Yassine

Reputation: 1887

Primefaces open p:fileUpload programmatically

I'm using tinyMCE, and i'm implementing a custom file manager. I would like to trigger the Choose button of the p:fileUpload (it is hidden) when the user clicks on the Browse button in the tinyMCE window.

<h:form enctype="multipart/form-data">
    <p:fileUpload id="fileUpload" widgetVar="fileUpload"/>
</h:form>

And here is the Javascript code i'm trying: PF('fileUpload').chooseButton.click() But it wouldn't trigger the Choose button. I tried on both Chrome and Firefox. How can I trigger the Choose button programmatically from javascript?

Upvotes: 2

Views: 3021

Answers (3)

Mohammad Fneish
Mohammad Fneish

Reputation: 989

Best practice from PF docs:

<p:fileUpload id="pf-file-upload" widgetVar="pf-file-upload" mode="advanced".../>

<p:button value="Upload" icon="pi pi-pencil"
onclick="return PF('pf-file-upload').show();"/>

Upvotes: 0

Wellington Alves
Wellington Alves

Reputation: 11

I used this solution:

PF('fileUpload').input.click()

Upvotes: 1

Attila Moln&#225;r
Attila Moln&#225;r

Reputation: 144

Just faced this problem, this solution has worked for me:

onclick="$('input[type=file]').click();"

Upvotes: 3

Related Questions