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
skiershortyskiershorty 

VF page Picklist inputField onchange apex method not executed required fields exist.

We have a custom object that has fields that should only be visible based on a custom select or a picklist. When the Custom Object fields are required or an inputField is marked as required the onchange event does not execute. Adding immediate="true" to the actionFunction also doesn't allow the onchange to execute.

 

Using the built in Account object also produces the same result. The desired result for this example is to hide the Billing City field when Web is selected from the picklist. This works until the accountName section, which contains a required field, is uncommented then the field is not hidden when Web is selected. Is there a missing attribute or additional setting required?

 

Thanks

 

Visualforce***************************************************

<apex:page controller="AccountTest">
  <apex:form >
      <apex:pageBlock >
            <apex:actionFunction action="{!getSelection}" rerender="accountName" name="callSelection"/>
            <apex:pageBlockSection title="Account Information" id="testing" Columns="1">                
                <apex:inputField id="accountSource" value="{!account.AccountSource}" onchange="callSelection(this.value);"/>
            </apex:pageBlockSection>
           <apex:pageBlockSection columns="1" id="accountName">
                <apex:inputField value="{!account.BillingCity}" rendered="{!isVisible}"/>
           </apex:pageBlockSection>
           <!--***Comment Out This Section***-->
           <!--
           <apex:pageBlockSection title="Account Name" id="accountName" columns="1" >
                <apex:inputField value="{!account.Name}" rendered="{!isVisible}"/>
           </apex:pageBlockSection>
           -->
           <!--***Comment Out This Section***-->
       </apex:pageBlock>
  </apex:form>
</apex:page>

 

Apex***********************************

public class AccountTest {
    public Account account {get;set;}
   
    public AccountTest(){
        this.account = new Account();
    }
   
    public boolean getIsVisible(){
        return Account.AccountSource != 'Web';
    }
   
    public PageReference getSelection()
    {
        system.debug('getSelection');
        Account.BillingCity =  Account.AccountSource;
        return null;
    }
}