You need to sign in to do that
Don't have an account?
Kishore Vamsi 6
I am new to VF code, I have tried above code but it is not working for me. If I select true radio button then account name should be display and if I select false then it should be disabled
I want to disable field when I select false radio button
public class sampleCons { public string selectedValue {get;set;} public boolean isDisabled{set;get;} public sampleCons(ApexPages.StandardController controller){ isDisabled=true; } public PageReference test() { if(selectedValue == 'True'){ // perfom your logic here system.debug('====>'+selectedValue); isDisabled=true; } else if (selectedValue == 'False'){ system.debug('====>'+selectedValue); isDisabled=false; // perform your logic here } return null; } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('True','True')); options.add(new SelectOption('False','False')); system.debug('====>'+options); return options; } }
<apex:page standardController="Account" extensions="sampleCons"> <apex:form id="myForm"> <apex:pageMessages /> <apex:selectRadio value="{!selectedValue}"> <apex:selectOptions value="{!items}"> </apex:selectOptions> </apex:selectRadio><p/> <apex:pageBlock title="Edit Contact" rendered="{!isDisabled}"> <apex:pageBlockSection columns="1"> <apex:inputField value="{!account.name}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
I am new to VF code, I have tried above code but it is not working for me. If I select true radio button then account name should be display and if I select false then it should be disabled
Else refer below code, I have moved the logic to aother field "Type". But still you need to first provide the value in Name Field as you have selected standard controller so all the validation are automatic getting fired and you can not by pass the mandatory field.
Previous example will also work just provide some value in field.
If you find the above solution helpful. Please mark as Best Answer to help others too.
Thanks and Regards,
Santosh Kumar
All Answers
https://help.salesforce.com/articleView?id=000324662&type=1&mode=1
If it helps please like and mark as correct, it may help others with the same question
Refere the below snippet, I have done slight chnages in your code :
And VF page below :
So the main differece in both the code is I have used action:support and rerender attribute of action:support.
So if you are wondering what it does is, when you are selecting value as 'True' or 'False' you need to tell DOM that it should referesh.
Rendered is use to show and hide the component but we need to let the DOM know when to do it.
So reRender tells the dom that changes are done, so refresh the DOM.
If you find the above solution helpful. Please mark as Best Answer to help others too.
Thanks and Regards,
Santosh Kumar
Thanks for the quick response.
The above code is not working, when i select false radio button I think we are not able to capture onchange value. Any way thanks for your help.
The sample code posted by you is not your exact code and I guess you are trying to merge the logic in your code and missing out something.
So just give it a try by using my code directly create a class "sampleCons" and a VF page "sampleConsVf" and paste my code as it is if it doesn't work for you then let me know I can help you out.
I have copied same code in my instance but it is not working for me. Please see below screen shot. Even if I select false it is showing below field
Else refer below code, I have moved the logic to aother field "Type". But still you need to first provide the value in Name Field as you have selected standard controller so all the validation are automatic getting fired and you can not by pass the mandatory field.
Previous example will also work just provide some value in field.
If you find the above solution helpful. Please mark as Best Answer to help others too.
Thanks and Regards,
Santosh Kumar