Thanks in advance
VF Page--
<apex:page standardController="Document" extensions="MyDocuments">
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!len}" size="1">
<apex:selectOptions value="{!option}"/>
<apex:actionSupport event="onchange" action="{!uploadMultiFile}" reRender="lab"/>
</apex:selectList>
</apex:pageBlock>
<apex:pageBlock title="UpLoad A File">
<apex:pageBlockSection id="lab">
<apex:repeat value="{!total}" var="t">
<apex:inputFile value="{!doc.body}" fileName="{!doc.name}"/>
</apex:repeat>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
---------------------------------------------------------------------------------------------------------------------
Controller--
public class MyDocuments {
public document doc {get;set;}
public List<selectOption> option {get;set;}
public String len {get;set;}
public Integer total {get;set;}
public MyDocuments(ApexPages.StandardController controller)
{
doc = (Document)controller.getRecord();
doc.folderId = UserInfo.getUserId();
option = new List<selectOption>();
option.add(new selectOption('','--None--'));
for(Integer i=1; i<=10; i++)
{
option.add(new selectOption('val'+i,string.valueOf(i)));
}
}
public void uploadMultiFile()
{
if(len == 'val1')
{
total = 1;
}
if(len == 'val2')
{
total = 2;
}
}
}
Hi Sandeep,You can not rerender inputFile using actionsupport, so you have to use javascript for this.Check below code for your reference and change this as per your requirment. <apex:page standardController="Document" extensions="MyDocuments">
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!len}" size="1" onchange="showFiles();" styleClass="fileCount">
<apex:selectOptions value="{!option}"/>
</apex:selectList>
</apex:pageBlock>
<apex:pageBlock title="UpLoad A File">
<apex:pageBlockSection id="lab">
<apex:repeat value="{!intTotal}" var="t">
<apex:inputFile value="{!doc.body}" fileName="{!doc.name}" style="display:none" styleclass="file_{!t} files"/>
</apex:repeat>
<br />
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
function showFiles(){
var fileCount = jQuery(".fileCount").val();
//alert(fileCount )
jQuery(".files").hide();
jQuery(".files").val('');
for(i=1; i<=fileCount;i++){
jQuery(".file_"+i).show();
}
}
</script>
</apex:page>
Hope this will help you. Let me know if it helped or you need any more assistance. Please mark this is as the solution if it solved your purpose.Thanks,Sohan Raj Guptapublic class MyDocuments {
public document doc {get;set;}
public List<selectOption> option {get;set;}
public String len {get;set;}
public List<Integer> intTotal {get; set;}
public MyDocuments(ApexPages.StandardController controller)
{
doc = (Document)controller.getRecord();
doc.folderId = UserInfo.getUserId();
option = new List<selectOption>();
option.add(new selectOption('','--None--'));
intTotal = new List<Integer>();
for(Integer i=1; i<=10; i++)
{
option.add(new selectOption(string.valueOf(i),string.valueOf(i)));
intTotal.add(i);
}
}
}