You need to sign in to do that
Don't have an account?
mac admin
How to Show / Hide the fields when the checked in Vfpage
Hi all,
I want to show the fields when a check box is check and hide the fields when the checkbox is uncheck. Below is my vfpage and extenstion class.
Error: Compile Error: unexpected token: 'If' at line 13 column 5
Can anyone help me over here.
Thanks in advance.
Regrads,
mac.
I want to show the fields when a check box is check and hide the fields when the checkbox is uncheck. Below is my vfpage and extenstion class.
<apex:page standardController="Account" extensions="constructor"> <apex:form > <apex:pageBlock Title="Account Checkbox Test"> <apex:pageBlockSection id="Selected_PBRS"> <apex:inputCheckbox value="{!account.Port__c}" id="checkedone"> <apex:actionSupport event="onchange" rerender="Fieldrender" action="{!Fieldupdate}"/> </apex:inputCheckbox> <apex:inputText value="{!account.Score__c}" rendered="{!field}" id="Fieldrender"/> <apex:inputText value="{!account.Review__c}" rendered="{!field}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
public class constructor{ public Boolean Portfolio{get; set;} public Boolean field {get;set;} public string Score {get;set;} public string Review {get;set;} public constructor(ApexPages.StandardController controller) { } Public constructor() { field=true; } public void Fieldupdate{ If(account.Port__c == true){ field=false; }else{ field=true; } } }I have been facing the error as below.
Error: Compile Error: unexpected token: 'If' at line 13 column 5
Can anyone help me over here.
Thanks in advance.
Regrads,
mac.
<apex:page standardController="Account" extensions="constructors">
<apex:form >
<apex:pageBlock Title="Account Checkbox Test">
<apex:pageBlockSection id="Selected_PBRS">
<apex:inputCheckbox value="{!account.Port__c}" id="checkedone">
<apex:actionSupport event="onchange" rerender="Selected_PBRS" action="{!Fieldupdate}"/>
</apex:inputCheckbox>
<apex:inputText value="{!account.Score__c}" rendered="{!field}" id="Fieldrender"/>
<apex:inputText value="{!account.Review__c}" rendered="{!field}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class constructors{
Public account acc{get;set;}
public Boolean Port{get; set;}
public Boolean field {get;set;}
public constructors(ApexPages.StandardController controller)
{
acc = (Account) Controller.getRecord();
field =true;
}
public void Fieldupdate(){
If(acc.Port__c == true){
field=false;
system.debug('@@@@Field value:'+field);
}else{
field=true;
system.debug('@@@@Field value:'+field);
}
}
}
All Answers
public void Fieldupdate ( )
{
If(account.Port__c == true)
{ field=false; }
else
{ field=true; }
}
You have check the below code,I think it will works for you,
<apex:page standardController="Account" extensions="ShowHidebasedoncheckboxext">
<apex:form >
<!-- Action status for displaying loading Image --->
<center><apex:actionStatus id="actStatusId" style="width:500px;height:500px;">
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus></center>
<apex:pageBlock Title="Account Checkbox Test">
<apex:pageBlockSection id="Selected_PBRS">
<apex:inputCheckbox value="{!account.Active__c}">
<apex:actionSupport event="onchange" rerender="Fieldrender" action="{!Fieldupdate}" status="actStatusId"/>
</apex:inputCheckbox>
</apex:pageBlockSection>
<apex:outputPanel id="Fieldrender">
<apex:outputPanel rendered="{!field ==true}">
This place you have to add your fields.
This part will hide when check the checkbox
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ShowHidebasedoncheckboxext{
public Boolean field {get;set;}
Public account acc{get;set;}
public ShowHidebasedoncheckboxext(ApexPages.StandardController controller) {
acc= new account();
field=true;
}
public void Fieldupdate(){
if(acc.Active__c == true) {
field=true;
system.debug('@@@@Field value:'+field);
}
else{
field=false;
system.debug('@@@@Field elase partvalue:'+field);
}
}
}
Thanks,
Raghavendra Reddy.D
Thanks for the reply. I have changed the code as you mentioned but I'm facing the error as below.
Attempt to de-reference a null object
Error is in expression '{!Fieldupdate}' in page checkbox_verify: Class.constructors.Fieldupdate: line 14, column 1
can you please send your code? why because I am not getting any error I will check my org then only I replied your answer.
Thanks,
Raghavendra Reddy.D
public ShowHidebasedoncheckboxext(ApexPages.StandardController controller) {
acc= new account();
field=true;
}
Below is my controller which i have as you mentioned.
public class constructors{
Public account acc{get;set;}
public Boolean Port{get; set;}
public Boolean field {get;set;}
public constructors(ApexPages.StandardController controller) { }
Public constructors() {
acc= new account();
field=true;
}
public void Fieldupdate(){
If(acc.Port__c == true){
field=false;
system.debug('@@@@Field value:'+field);
}else{
field=true;
system.debug('@@@@Field value:'+field);
}
}
}
In vfpage you have to directly take <apex:inputCheckbox value="{!account.Port__c}"> , dont take boolean values.
<apex:inputCheckbox value="{!account.Port__c}">
<apex:actionSupport event="onchange" rerender="Fieldrender" action="{!Fieldupdate}" status="actStatusId"/>
</apex:inputCheckbox>
Thanks,
Raghavendra Reddy.D
<apex:page standardController="Account" extensions="constructors">
<apex:form >
<apex:pageBlock Title="Account Checkbox Test">
<apex:pageBlockSection id="Selected_PBRS">
<apex:inputCheckbox value="{!account.Port__c}" id="checkedone">
<apex:actionSupport event="onchange" rerender="Selected_PBRS" action="{!Fieldupdate}"/>
</apex:inputCheckbox>
<apex:inputText value="{!account.Score__c}" rendered="{!field}" id="Fieldrender"/>
<apex:inputText value="{!account.Review__c}" rendered="{!field}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class constructors{
Public account acc{get;set;}
public Boolean Port{get; set;}
public Boolean field {get;set;}
public constructors(ApexPages.StandardController controller)
{
acc = (Account) Controller.getRecord();
field =true;
}
public void Fieldupdate(){
If(acc.Port__c == true){
field=false;
system.debug('@@@@Field value:'+field);
}else{
field=true;
system.debug('@@@@Field value:'+field);
}
}
}
Thanks for the reply, It's working but by default the text fields should be hidden only when the checkbox is checked then only the fields should display. Can you help me on this.
Thanks in advance.
Regards,
mac.
I got the solution for which i asked you in previous reply.
Regrads,
mac.