0

I have an inputfile component and a commandbutton with an action to upload a file. My users dislike the appearance of the inputfile component and want the upload dialog to be fired up when the commandbutton is pressed. I'm thinking this possible; just fire the event and store the value in a hidden inputfile component. I'm not sure how to fire the event though.

Here is some of my vf code:

`
Attachments

<apex:commandButton styleClass="btn btn-outline-primary text-uppercase"  value="Upload Attachment" action="{!UploadAttachment}" />                                        

<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" styleClass="support-case-form-control" />                                        
<br/><br/>

<apex:outputtext >.PNG, .GIF, .JPEG ATTACHMENTS ACCEPTED</apex:outputtext><br/>
<apex:outputtext > MAXIMUM SIZE = 25MB</apex:outputtext>                                                                                                                                                                                                                                                                                                                                                                                      

`

0

The second link pretty much spelled it out. I just didn't how to fire the event and it was simple enough just like you would do it for anything else. I thought there was another fancy way with apex, like a callout or something. So many ways.

Here is the link again and the code: developer.salesforce.com/forums/?id=906F0000000ASMsIAO

<apex:form >
    <script language="JavaScript" type="text/javascript">
        function HandleBrowseClick()
        {
            var fileinput = document.getElementById("{!$Component.SnapshotInputfile}");
            fileinput.click();
        }

        function Handlechange()
        {
            var fileinput = document.getElementById("{!$Component.SnapshotInputfile}");
            var textinput = document.getElementById("filename");
            textinput.innerHTML = fileinput.value;
        }
    </script>


    <apex:inputfile id="SnapshotInputfile" value="{!snapshot_attachment.body}"  onChange="Handlechange();" accept="image/*" filename="{!snapshot_attachment.Name}">            
    </apex:inputfile>
    <label id="filename" readonly="true"/>
    <input type="button" value="select" id="fakeBrowse" onclick="HandleBrowseClick();" class="btn"/>

    <apex:commandButton id="uploadButton" action="{!UploadPicture}" value="upload"/>
</apex:form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy