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
SFDC_LearnerSFDC_Learner 

Immediate = true not working

When i click on "Yes" radio i need to show the section that is having required field. When im clicking on "No" i need to hide the section.  But it is working fine when i click on "Yes" and when i click on "No" the required field asking a value.

 
Can you pleae correct the code :
 
 
Page:
 
<apex:page controller="SelectRadioclass" id="p1">
    <script>
        function InvoiceAddr(){
            alert('hi');
            document.getElementById('p1:f1:btnsearchforlonglat').click();  
        }
    </script>
 
      <apex:form id="f1">
          <apex:SelectRadio value="{!AddressOption}" onclick="InvoiceAddr();" >
                <apex:selectOptions value="{!yesno}"/>  
          </apex:SelectRadio>
 
      
      <apex:actionFunction name="test" action="{!InvoiceAddress}" /> 
     <apex:commandButton value="test" id="btnsearchforlonglat"  onclick="test();" immediate="true"  style="display:none;" />
           
     
      <apex:pageblock >
          <apex:pageblockSection title="Billing Address" rendered="{!BillingBool}" >
                                    <apex:inputField value="{!Acct.ShippingCity}" required="true"/>  
                    </apex:pageblockSection> 
       </apex:pageblock>
            
     </apex:form>
</apex:page>
 
 
class:
 
 
public with sharing class SelectRadioclass {
 
    public pagereference InvoiceAddress(){
               system.debug('---entered--');
                if(AddressOption == 'true'){
                    system.debug('---true--');
                     BillingBool = true;
                }else{ 
                          system.debug('---false--');
                          BillingBool = false;
                }
                return null;
       }              
               
 
               
 
 
    public boolean BillingBool { get; set; }
    public Account Acct{get;set;}
    
    public SelectRadioclass(){
        acct = new Account();
    }
     public List<SelectOption> getYesNo() {
                List<SelectOption> options = new List<SelectOption>();
                 options.add(new SelectOption('true', 'Yes'));
                 options.add(new SelectOption('false', 'No'));
                 
                return options;
                  }
 
 
    public String AddressOption { get; set; }
}
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

immediate="true" will also discard any input, which doesn't sound like the behaviour you are looking for. If you want to avoid validation on required fields, an action region is a better solution:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm

All Answers

bob_buzzardbob_buzzard

immediate="true" will also discard any input, which doesn't sound like the behaviour you are looking for. If you want to avoid validation on required fields, an action region is a better solution:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm

This was selected as the best answer
SFDC_LearnerSFDC_Learner

Perfect!