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
Naofumi KunNaofumi Kun 

Disable a field depending on a Picklist value in Apex

Hi I need your help here.

We need to have schedule.Start_Date__c disabled when schedule.Products_Offer__c == 'Product B'.

Also, I would like to know if it is possible that it will be disabled as soon as I select the Picklist Product B.
 
<apex:actionRegion>
<div class="slds-truncate" title="">
	<apex:inputField style="width:90px;" value="{!schedule.Start_Date__c}" rendered="{!schedule.Products_Offer__c != 'Willow Rail Platform'}">
		<apex:actionSupport event="onchange" rerender="tableId" status="status"/>
	</apex:inputField>
	<apex:outputField style="width:90px;" value="{!schedule.Start_Date__c}" rendered="{!schedule.Products_Offer__c == 'Willow Rail Platform'}">
		<apex:actionSupport event="onchange" rerender="tableId" status="status"/>
	</apex:outputField>
</div>
</apex:actionRegion>
Any kind of help is much appreciated!
 
sumithasumitha
Hi,

try to add outputpanel:

<apex:outputPanel rendered="{!if(!schedule.Products_Offer__c= 'Product B',true,false)}">
 <apex:inputField style="width:90px;" value="{!schedule.Start_Date__c}" rendered="{!schedule.Products_Offer__c != 'Willow Rail Platform'}">
</apex:outputPanel>

Hope it Helps you.
If it is helpful information.Please mark as Best Answer

Thanks
Sumitha P
Naofumi KunNaofumi Kun
Hi Sumitha,

I got the following error when I try to use your code.
Error: Incorrect parameter type for function 'not()'. Expected Boolean, received Text

 
sumithasumitha
Hi,

<apex:outputPanel rendered="{!if(!schedule.Products_Offer__c== 'Product B',true,false)}">
Include '==' in the above line.

Thanks
Sumitha P
Naofumi KunNaofumi Kun
Still getting the same error.

I think the system is not accepting
 
<apex:outputPanel rendered="{!if(!schedule.Products_Offer__c== 'Product B',true,false)}">
Because the true and false value are actual text

 
sumithasumitha
Hi,

<apex:outputPanel rendered="{!if(schedule.Products_Offer__c== 'Product B',true,false)}">

Try this i have Excluded ""!".
 and working on my end.

Thanks
Sumitha 
Naofumi KunNaofumi Kun
Appreciate your help here.

The results are the just disappear regardless of the current of the Picklist
sumithasumitha
Sure.May be Outputfied rendered and Outputpanel rendered gets override.

Thanks