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
Manoj DeshmukhManoj Deshmukh 

we select in user lookup can only edit/change values from 2nd and 3rd field

Create 3 fields on VF page. One is lookup to user, 2nd is picklist and 3rd one is text field

Now, we need to implement the functionality like as below

The person that we select in user lookup can only edit/change values from 2nd and 3rd field. In case of other user, other than selected user in user lookup, user cannot change the value. Instead it will come as readonly
RKSalesforceRKSalesforce
Hi Manoj,

Please use below code:
<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock >
            <apex:pageblockSection >
                <apex:outputField value="{!Account.Custom_Owner__c}"  />
            </apex:pageblockSection>
            
            
        </apex:pageBlock>
        <apex:pageBlock >
            <apex:pageblockSection rendered="{!Account.Custom_Owner__c = $User.Id}" >
                <apex:outputField value="{!Account.Name}" />
                <apex:outputField value="{!Account.AccountNumber}" />
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Account.Custom_Owner__c != $User.Id}">
                <apex:outputField value="{!Account.Name}" html-disabled="true"/>
                <apex:outputField value="{!Account.AccountNumber}" html-disabled="true"/>
            </apex:pageblockSection>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Please let me know if helped.

Regards,
Ramakant
Manoj DeshmukhManoj Deshmukh
Thnx Ramakant , but Actually we dont want use 3rd PageBlockSection cuz the fields are repeated again in the code.so is it possible only using 2nd PageBlockSection.
RKSalesforceRKSalesforce
Hi Manoj,

Please try below code:
<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock >
            <apex:pageblockSection >
                <apex:outputField value="{!Account.Custom_Owner__c}"  />
                <apex:outputField value="{!Account.Name}" rendered="{!Account.Custom_Owner__c = $User.Id}"/>
                <apex:outputField value="{!Account.AccountNumber}" rendered="{!Account.Custom_Owner__c = $User.Id}"/>   
                <apex:outputField value="{!Account.Name}" html-readonly="true" rendered="{!Account.Custom_Owner__c != $User.Id}"/>
                <apex:outputField value="{!Account.AccountNumber}" html-readonly="true" rendered="{!Account.Custom_Owner__c != $User.Id}"/>
            </apex:pageblockSection>
            </apex:pageBlock>
    </apex:form>  
</apex:page>

 
Manoj DeshmukhManoj Deshmukh
Actually we have above 100 fields in that object . So in our case every Field come as twice in PageBlockSection. so i am trying to implement through javascript but the field is not display read only when other user get selected. can you Please tell me whats wrong in my code
Manoj DeshmukhManoj Deshmukh
<apex:page standardController="Customer__c" id="thePage">
        <apex:form id="theForm">
        <apex:actionFunction name="refreshPage" rerender="theForm"/>
              <apex:pageBlock id="theBlock">
                     <apex:pageBlockSection id="theSec" >
                                    <apex:inputField value="{!Customer__c.User__c}"  id="accName" onchange="setResult();" />
                     </apex:pageBlockSection>
            <apex:pageblockSection id="theSec1">
                    <apex:inputField value="{!Customer__c.Name}" id="accName1" />
                    <apex:inputField value="{!Customer__c.Type__c}" />
                    
            </apex:pageblockSection>
              </apex:pageBlock>
              <script>
                       function setResult(){
                        var spans = document.getElementById('thePage:theForm:theBlock:theSec:accName').value;
                            if(spans != $User.Id){
                                document.getElementById('thePage:theForm:theBlock:theSec1:accName1').readOnly=true;
                               refreshPage();
                            }
                        }
                       
                </script>
         </apex:form>
</apex:page>