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
NewbyNewby 

Disable picklist and an input field based on a picklist value while creating a new record and modifying a record

Friends,

I have requirement to disable a picklist field and also clear and disable an input field based on a picklist value.
Say for example : I have picklist-1 and Picklist-2 and a textfield-1

so based on the value from picklist-1, I need to disable and enable  picklist-2 and textfield-1 on my visualforce page both during creating a record and while editing a record.
I have tried actionsupport but can only do rendering of a field, but not disabling and this worked only while editing the record.

It would be really helpful if one of you can help me with an example for the above senario. I am stuck with this issue for quite a long time.

Thanks in advance
MPM
Subramani_SFDCSubramani_SFDC
Try like this


------------------------------------Controller-------------------------------------
public class ShowSectionController
{
    public Account acc{get;set;}
    public boolean flag{get;set;}
    public ShowSectionController()
    {
        acc = new Account();
        flag = true;
      
    }
    public void hideSectionOnChange()
    {
        if(acc.married__c == 'Yes')
            flag = false;
        if(acc.married__c == 'No')
            flag = true;
    }
}
-----------------------------------------------------------------------------------------------
---------------------------------------VF page----------------------------------------------
<apex:page controller="ShowSectionController" tabStyle="Account">
  <apex:form >
  <Apex:actionFunction name="hideSection" action="{!hideSectionOnChange}" rerender="pg"/>

      <apex:pageBlock id="pg">
          <apex:pageBlockSection title="Select A">
              <apex:inputField value="{!acc.Married__c}" onchange="hideSection('{!acc.Married__c}')"/>
          </apex:pageBlockSection>
          <apex:pageBlockSection title="Section B" >
             <Apex:inputText label="Name" rendered="{!(!flag)}"/>
          </apex:pageBlockSection>
      
      </apex:pageBlock>
  </apex:form>
</apex:page>
---------------------------------------------------------------------------------------------------