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
RbnRbn 

Re:Checkbox Dependency

My req ::

is that i have a checkbox(NSURANCE TAKEN FOR LOAN),and when the
checkbox is checked then two fields should be enabled or else it
should be disabled

 

The two fields which are to be enabled are:

Insurance_Premium_Paid__c &  Insurance_Renewal_Date__c

CODE::


<apex:actionRegion >
                    <apex:inputField
value="{!Family__c.Insurance_taken_for_Loan__c}" id="insFlag">
                        <apex:actionSupport event="onchange"
rerender="insPremPaid,insRenDateOutput,insRenDateInput"
status="processingStatus"/>
                    </apex:inputField>
                </apex:actionRegion>
                </apex:pageBlockSectionItem>
                <apex:inputText
value="{!Family__c.Insurance_Premium_Paid__c}" id="insPremPaid"
disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>
                <apex:outputField
value="{!Family__c.Insurance_Renewal_Date__c}" id="insRenDateOutput"
rendered="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>
                <apex:inputField
value="{!Family__c.Insurance_Renewal_Date__c}" id="insRenDateInput"
rendered="{IF(!Family__c.Insurance_taken_for_Loan__c==TRUE,TRUE,FALSE)}"/>

Here the insurance renewal date is a date field.

My problem is i am NOT getting the Insurance renewal date field enabled
vhn m checking the checkbox.

Shiv ShankarShiv Shankar

We can use java script for it.

 

<apex:actionRegion >
                    <apex:inputField value="{!Family__c.Insurance_taken_for_Loan__c}" id="insFlag" onclick="enabelDisabel(this)">
                        <apex:actionSupport event="onchange" rerender="insPremPaid,insRenDateOutput,insRenDateInput" status="processingStatus"/>
                    </apex:inputField>
</apex:actionRegion>
                </apex:pageBlockSectionItem>
                <apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" id="insPremPaid" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>
                <apex:outputField value="{!Family__c.Insurance_Renewal_Date__c}" id="insRenDateOutput" rendered="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>

                
<script>
    function enabelDisabel(element){
        if(element.checked){
            $('[id $= "fieldName1"]').css('display','none');
            $('[id $= "fieldName2"]').css('display','none');
        }
        else{
            $('[id $= "fieldName1"]').css('display','block');
            $('[id $= "fieldName2"]').css('display','block');
        }
    }
</script>

amitashtekaramitashtekar

Hi,

 

Try out below thing

 

<apex:page controller="Check" >
<apex:form >
<apex:actionRegion >
<apex:inputCheckbox value="{!whetherChecked}" id="insFlag">
<apex:actionSupport event="onchange" rerender="op" status="processingStatus"/>
</apex:inputCheckbox>
<apex:outputPanel id="op">
<apex:inputText value="{!Text1}" id="inp1" disabled="{!!whetherChecked}"/>
<apex:outputText value="{!whetherChecked}" id="inp2" rendered="{!whetherChecked}"/>
<apex:inputText value="{!Text2}" id="inp3" disabled="{!!whetherChecked}"/>

</apex:outputPanel>
</apex:actionRegion>
</apex:form>
</apex:page>

 

Controller

 

public class Check
{

public String Text2 { get; set; }

public String Text1 {get;set;}

public Boolean whetherChecked{get;set;}
}