0

Im trying to give the 'choose file' button the lightning style,I tried to set the header on True,but its not working with that component. Is there any other way to do it?

<apex:form id="theForm">

  <apex:pageBlock >

      <apex:pageBlockSection >

        <apex:inputFile value="{!document.body}" filename="{!document.name}" styleClass="slds-file-selector__button"  / >

        <apex:commandButton value="Save" action="{!save}"/>

      </apex:pageBlockSection>



   </apex:pageBlock>

</apex:form>

1

You will have to import SLDS stylesheets to your visualforce page.

To add SLDS to your page, add the <apex:slds/> tag anywhere on your page. The <apex:slds/> tag imports SLDS stylesheets so you don’t have to do it yourself.

Also, there is more that needs to be done in order to give inputFile a lightning button look.

Below visualforce page should do the trick

<apex:page >
   <apex:form id="theForm">
      <apex:slds />
      <apex:pageBlock >
         <apex:pageBlockSection >
            <div class="slds-form-element">
               <span class="slds-form-element__label" id="file-selector-id">Attachment</span>
               <div class="slds-form-element__control">
                  <div class="slds-file-selector slds-file-selector_files">
                     <div class="slds-file-selector__dropzone">
                        <apex:inputFile styleClass="slds-file-selector__input slds-assistive-text" accept="image/png" id="fileUploadInput01" value="foo" />
                        <apex:outputLabel styleClass="slds-file-selector__body" for="fileUploadInput01">
                           <span class="slds-file-selector__button slds-button slds-button_neutral">
                              <svg class="slds-button__icon slds-button__icon_left" aria-hidden="true">
                                 <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#upload"></use>
                              </svg>
                              Upload Files
                           </span>
                           <span class="slds-file-selector__text slds-medium-show">or Drop Files</span>
                        </apex:outputLabel>
                     </div>
                  </div>
               </div>
            </div>
            <apex:commandButton value="Save" action="{!save}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>
</apex:page>

You can get further help on this topic at this link

  • Well, this does answer the question but uses a link which can break / change. Can you add some sample code snippet? – Pranay Jaiswal Mar 11 at 16:16
  • 1
    Yup Thanks @Pranay ! Updated the answer. – Vijay Ganji Mar 11 at 16:23
  • +1. Thanks... :) – Pranay Jaiswal Mar 11 at 16:24
  • Have you tried if it works? I don't think this works though. – Jayant Das Mar 11 at 16:24
  • @JayantDas it seems you are right. – Pranay Jaiswal Mar 11 at 21:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.