You need to sign in to do that
Don't have an account?
Code+1
Display Fields when Checkbox is checked
Hello All,
On Checkbox field check, I need to display a Date Field and File Upload section.
When the checkbox is unchecked, i need to remove the Date Field and File Upload Section..
I have written the below code, which works perfectly when the checkbox is checked.
When I uncheck the checkbos, it throws the error - "Visualforce Error Help for this Page
apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute."
VF Page
<apex:page standardController="Associate__c" extensions="AttachmentUploadController">
<apex:form >
<apex:pageBlock id="tBlock">
<apex:outputLabel value="Active" />
<apex:inputField value="{!Associate__c.Active__c}">
<apex:actionSupport event="onchange" rerender="tBlock"/>
</apex:inputField>
<br></br>
Date of Joining <apex:inputField value="{!Associate__c.DOJ__c}" rendered="{!(Associate__c.Active__c == true)}"/>
<br></br>
<apex:actionregion >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" rendered="{!(Associate__c.Active__c == true)}"/>
</apex:actionregion>
</apex:pageBlock>
Apex Class
public with sharing class AttachmentUploadController {
public AttachmentUploadController(ApexPages.StandardController controller) {
}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
// attachment.ParentId = '00190000015ZVLm'; // the record the file is attached to
attachment.ParentId = ApexPages.currentPage().getParameters().get('id');
attachment.IsPrivate = true;
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
Please help..
Thanks!
On Checkbox field check, I need to display a Date Field and File Upload section.
When the checkbox is unchecked, i need to remove the Date Field and File Upload Section..
I have written the below code, which works perfectly when the checkbox is checked.
When I uncheck the checkbos, it throws the error - "Visualforce Error Help for this Page
apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute."
VF Page
<apex:page standardController="Associate__c" extensions="AttachmentUploadController">
<apex:form >
<apex:pageBlock id="tBlock">
<apex:outputLabel value="Active" />
<apex:inputField value="{!Associate__c.Active__c}">
<apex:actionSupport event="onchange" rerender="tBlock"/>
</apex:inputField>
<br></br>
Date of Joining <apex:inputField value="{!Associate__c.DOJ__c}" rendered="{!(Associate__c.Active__c == true)}"/>
<br></br>
<apex:actionregion >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" rendered="{!(Associate__c.Active__c == true)}"/>
</apex:actionregion>
</apex:pageBlock>
Apex Class
public with sharing class AttachmentUploadController {
public AttachmentUploadController(ApexPages.StandardController controller) {
}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
// attachment.ParentId = '00190000015ZVLm'; // the record the file is attached to
attachment.ParentId = ApexPages.currentPage().getParameters().get('id');
attachment.IsPrivate = true;
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
Please help..
Thanks!
Yah, Can you please share me the code snippet / sample code using JavaScript.
It will be very helpful.
Thanks !!