Reputation: 1887
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
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
Reputation: 144
Just faced this problem, this solution has worked for me:
onclick="$('input[type=file]').click();"
Upvotes: 3