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
ShivaShiva 

How to make field readonly?

Based on the some condition I want to make few fields readonly. How in VF page?

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
TehNrdTehNrd
Your get method is returning a string. It should be returning a boolean.

All Answers

TehNrdTehNrd

If it is an inputText field you can use the attribute disabled="true".

 

If it is an inputField you will have to use an Input and outputField to achieve this result:

 

 

<apex:inputField value="{!Opportunity.Name}" rendered="{!NOT(disableName)}"/> <apex:outputField value="{!Opportunity.Name}" rendered="{!disableName}"/>

 

 

 

ShivaShiva
ErrorError: Incorrect parameter for function NOT(). Expected Boolean, received Text
ErrorError: Incorrect parameter for function NOT(). Expected Boolean, received Text
ErrorError: Incorrect parameter for function NOT(). Expected Boolean, received Text

Got this error

 

Error: Incorrect parameter for function NOT(). Expected Boolean, received Text

 

<apex:inputField rendered="{!NOT(renderOtherProject)}" value="{!cs_test__c.OtherProject__c}" />
<apex:outputField rendered="{!renderOtherProject}" value="{!cs_test__c.OtherProject__c}" />

 

In the controller: Here it it is setting proper values.

 

public string renderOtherProject
    {
        get
        {   String renderOtherProject= 'true';
            System.debug(Logginglevel.DEBUG,'In If lickey.GenStatus__c:' + lickey.GenStatus__c);
            if (lickey.GenStatus__c=='ok')
              renderOtherProject='false';

                System.debug(Logginglevel.DEBUG,'In If renderOtherProject ' + renderOtherProject);
            return renderOtherProject; 
        }
        set;
    }

TehNrdTehNrd
Your get method is returning a string. It should be returning a boolean.
This was selected as the best answer
ShivaShiva
Thanks