function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Soumya sri yaravaSoumya sri yarava 

Runtime Errror while using APEX:INPUTFILE, How can i handle this??

hi guys i got below Error:
apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

 
public class InputfileExample {
 public blob uploadedfile{get;set;}
 public string filename{get;set;}
 public string name{get;set;}
 public string branch{get;set;}
  
   public void submit(){
    system.debug(name);
    system.debug(branch);
    system.debug(uploadedfile);
    system.debug(filename);
  }
}

Visual Froce page:
<apex:page controller="InputfileExample">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<apex:form id="one" >
    Entername:<apex:inputText value="{!name}" id="name"/> <br/><br/>
    EnterBranch:<apex:inputText value="{!branch}" id="branch"/><br/><br/>
    ChooseFile:
   <apex:inputFile id="fileUplaod" value="{!uploadedfile}"  filename="{!filename}"  accept=".jpeg,.png,.jpg"> </apex:inputFile><br/><br/>
  
    <script>
      function callme(){
        var addname =$('[id$=name]').val(); 
        var branch =$('[id$=branch]').val();
         if(addname ==''){
            alert('name is required');
          }else if(branch ==''){
            alert('branch is required');
           }else{
              submitcall();
            }
       }
     </script>
  <apex:actionFunction name="submitcall" action="{!submit}"  reRender="one"/>
  <apex:commandButton value="Submit" onclick="callme();" RERender="T" />
  </apex:form>
</apex:page>
Please provide a solution for this ,
thanks 
soumya.
 
David Zhu 🔥David Zhu 🔥
You will have to remove reRedner attribute from actionFunction and commandButton compnent.
Change line 22 and 23 to:

  <apex:actionFunction name="submitcall" action="{!submit}"/>
  <apex:commandButton value="Submit" onclick="callme();"  />

 
David Zhu 🔥David Zhu 🔥
To make it work you need to change line 22 and line 23 to:

<apex:actionFunction name="submitcall" action="{!submit}"/>
  <apex:commandButton value="Submit" onclick="callme();return false;"  />
Soumya sri yaravaSoumya sri yarava
hi David Zhu, the suggestion you have given is good, but after clicking on the submit button, the image is getting clear, how can i get rid of this issues.. if rerender is there , it  will stay in the  choose file.. can u please suggest me to handle this.

thanks
soumya...!
David Zhu 🔥David Zhu 🔥
Not sure what you meant ", the image is getting clear"? Once you clicked the button, apex method "submit" called after jquery checking.. is it not you want?
Soumya sri yaravaSoumya sri yarava
Before clicking on the submit button , 
   User-added image


After clicking on the submit button:

User-added image

the image file selected is getting clear from the scren ,as the screen load, can u pleae suggest some tipes 
thank you
soumya sree
David Zhu 🔥David Zhu 🔥
That is a limitation of VF page.
Soumya sri yaravaSoumya sri yarava
Any alternate solution, can i use the image of html to send it, please provide any solutions for that 
thanks