You need to sign in to do that
Don't have an account?

How to check a checkbox based on a picklist value on VF page?
Hi All
I'm trying to check a checkbox based on a picklist field value and vice versa, I'm using a VF page with a Standard controller and an extension and some Java Script, I'm relatively new to this so please bear with me. I think I'm heading in the right direction but messing up somewhere along the way.
Please see the code snippets below and advise where I'm going wrong/how can I achieve this? The Quality_Issue__c is the picklist and Quality_Reporting_Only__c is the checkbox that needs to be checked.
Extension class
I'm trying to check a checkbox based on a picklist field value and vice versa, I'm using a VF page with a Standard controller and an extension and some Java Script, I'm relatively new to this so please bear with me. I think I'm heading in the right direction but messing up somewhere along the way.
Please see the code snippets below and advise where I'm going wrong/how can I achieve this? The Quality_Issue__c is the picklist and Quality_Reporting_Only__c is the checkbox that needs to be checked.
Extension class
public class ClientSupportController { public Case ClientSupportCase {get;set;} public User UserID {get;set;} public ApexPages.StandardController controller{get;set;} public ClientSupportController(ApexPages.StandardController controller) { ClientSupportCase = new Case(); this.controller = controller; } public PageReference saveClientSupportCase () { try{upsert (ClientSupportCase); } catch (System.DmlException e) { ApexPages.addMessages(e); return null; } PageReference redirectSuccess = new ApexPages.StandardController(ClientSupportCase).view(); return (redirectSuccess); } public void QualityCheckboxSelction () { System.debug('>>>>>>>>>'); if (ClientSupportCase != null) { System.debug('ClientSupportCase.QualityIssue >>>>>>>>> ' + ClientSupportCase.Quality_Issue__c); if(ClientSupportCase.Quality_Issue__c == 'Yes') { ClientSupportCase.Quality_Reporting_Only__c = true ; } else if (ClientSupportCase.Quality_Issue__c == 'None') { ClientSupportCase.Quality_Reporting_Only__c = false ; } } } }VF Page :
<apex:page standardController="Case" extensions="ClientSupportController" showHeader="true" sidebar="true" tabStyle="Case" title="New Case" > <script type="text/javascript"> function selectionActionQualityCheckbox(valueCheckQualityReporting) { if(valueCheckQualityReporting == false) { callMethodQualityCheckbox(); } } </script> <apex:form > <apex:pageBlock title="Case Edit" > <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!saveClientSupportCase}" /> <apex:commandButton value="Cancel"/> </apex:pageBlockButtons> <apex:actionfunction name="callMethodQualityCheckbox" action="{!QualityCheckboxSelction}" reRender="id_SectionSnapshot"> </apex:actionFunction> <apex:actionfunction name="callMethodQualityCheckbox" action="{!QualityCheckboxSelction}" reRender="IncidentManagement"> </apex:actionFunction> <apex:pageBlockSection title="Case Snapshot" id="id_SectionSnapshot"> <apex:pageblocksectionitem > <apex:outputLabel value="Case Record Type" style="font-weight:Bold;padding-right:14px;" /> <apex:outputField value="{!ClientSupportCase.RecordTypeid}" /> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputLabel value="Case Owner" style="font-weight:Bold;padding-right:14px;" /> <apex:inputField value="{!ClientSupportCase.ownerid}" /> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputLabel value="Status" style="font-weight:Bold;padding-right:14px;" /> <apex:inputField value="{!ClientSupportCase.Status}" /> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputLabel value="Quality Issue" style="font-weight:Bold;padding-right:14px;" /> <apex:inputField value="{!ClientSupportCase.Quality_Issue__c}" onchange="selectionActionQualityCheckbox(this.value)" id="shiva1"/> </apex:pageblocksectionitem> </apex:pageBlockSection> <apex:pageBlockSection title="Incident Management" id="IncidentManagement"> <apex:pageblocksectionitem > <apex:outputLabel value="Impact" style="font-weight:Bold;padding-right:14px;" /> <apex:inputField value="{!ClientSupportCase.Impact__c}"/> </apex:pageblocksectionitem> <apex:pageblocksectionitem > <apex:outputPanel > <apex:outputLabel value="Quality Reporting - No Assistance Needed" style="font-weight:Bold;padding-right:14px;" /> <apex:inputField value="{!ClientSupportCase.Quality_Reporting_Only__c}" onchange="selectionActionQualityCheckbox(this.value)"/> </apex:outputPanel> </apex:pageblocksectionitem> </apex:pageBlockSection>
you have to use if like that:
Here are an example for you: The "IF-condition" works in SF a little bit foreign.
"=" is for comparison
I hope I can help you a little bit,
Lisa
Not sure if you can use same actionfunction/method to this functionality.
Please check below modified Controller extension and VF page.
VF Page:
Class:
Let me know if that works for you.
Best Regards,
BALAJI