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
Olivia FordeOlivia Forde 

readonly field on edit page

I have a Visualforce Edit Page and I want some of the fields to display readonlyI have tried this
<apex:outputfield value="{!Item.Item_Code__c}"/> but it only displays the label
Best Answer chosen by Olivia Forde
Sameer Tyagi SFDCSameer Tyagi SFDC
Hi Olivia,

Can you please share your Controller code with us?

Because you are using two objects

editItem
and
item

and try this 

<apex:outputfield value="{!EditItem.Item_Code__c}"/>

With the URL of record on page

Sameer
 

All Answers

MithunPMithunP
Hi Olivia Forde,

Use this
<apex:outputLabel value="SampleLabel"/>
<apex:outputText value="{!Item.Item_Code__c}"/> 

Best Regards,
Mithun.
Olivia FordeOlivia Forde
Hi
Tried this now but it displays the Label twice now but no data value for the field
Sameer Tyagi SFDCSameer Tyagi SFDC
Hi Olivia. 

It will show you only label of the read only field, If you are creating a record first time from your page because at that time value is not calculated. 

However if you are editing the same record through your page and ID is mentioned in URL then you will be able to see Read only field value also

for Example 
Your VF page name is myvfpage
You have read only field name is Item Code, which is an auto number type field or formula field. 

You are creating record first time with this URL
https://finacastapp.ap1.visual.force.com/apex/myvfpage
then Item code is not generated, because it will generate if you save that record. At that time it will show you label only 

Now your record is created and you are using this URL 
https://finacastapp.ap1.visual.force.com/apex/myvfpage?id=906F0000000Adf
It will display you that read only field value on VF page. 


Thanks & Regards, 
Sameer Tyagi. 
http://mirketa.com




 
MithunPMithunP
Hi Olivia Forde,

Not sure why it is displaying two labels, can you share your code.

If you want label with value use pageBlockSection.
 
<apex:page standardController="Account">
  <apex:pageBlock>
  <apex:pageBlockSection>
    <apex:outputText value="{!account.name}"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

Best Regards,
Mithun.
Sameer Tyagi SFDCSameer Tyagi SFDC
and the Tag you are using is correct 
<apex:outputfield value="{!Item.Item_Code__c}"/>

Sameer
 
Olivia FordeOlivia Forde
           <apex:pageBlockSection title="Global Marketing" columns="2">
       
                    <apex:pageBlockSectionItem helpText="Full Name of the Item to be added to GP and used on Invoices and Marketing Material">
                      <apex:outputLabel value="Item Name"/>
                      <apex:inputField value="{!editItem.Name}" required="true"/> 
                    </apex:pageBlockSectionItem>  
                      <apex:inputField value="{!editItem.Target_Cost_Price__c}" required="true"/>                   
                      <apex:outputLabel value="Item Code"/>
                      <apex:outputText value="{!Item.Item_Code__c}"/> 

                      <apex:inputField value="{!editItem.Target_Cost_of_Goods__c}" required="true"/>
                      <apex:inputField value="{!editItem.SIGW__c}"/>

                     
                      
                 
       </apex:pageBlockSection>
MithunPMithunP
Hi Olivia Forde,

Below is the updated version. I have tested in my org it's working fine.
 
<apex:pageBlockSection title="Global Marketing" columns="2">
       
                    <apex:pageBlockSectionItem helpText="Full Name of the Item to be added to GP and used on Invoices and Marketing Material">
                      <apex:outputLabel value="Item Name"/>
                      <apex:inputField value="{!editItem.Name}" required="true"/> 
                    </apex:pageBlockSectionItem> 
                   
                    <apex:pageBlockSectionItem> 
                      <apex:inputField value="{!editItem.Target_Cost_Price__c}" required="true"/> 
                    </apex:pageBlockSectionItem> 
                   
                    <apex:pageBlockSectionItem>                  
                      <apex:outputLabel value="Item Code"/>
                      <apex:outputText value="{!Item.Item_Code__c}"/> 
                   </apex:pageBlockSectionItem> 
                   
                    <apex:pageBlockSectionItem> 
                 <apex:outputLabel value="Target"/>
                      <apex:inputField value="{!editItem.Target_Cost_of_Goods__c}" required="true"/>
                      </apex:pageBlockSectionItem> 
                      
                      <apex:pageBlockSectionItem> 
 <apex:outputLabel value="SIGW"/>
                      <apex:inputField value="{!editItem.SIGW__c}"/>
                      </apex:pageBlockSectionItem> 

                            
       </apex:pageBlockSection>


Best Regards,
Mithun.
Olivia FordeOlivia Forde


EditItem

This is what I get
 
Sameer Tyagi SFDCSameer Tyagi SFDC

To test it you'll need the ID of one of your custom objects.  If you open one the url will look something like this:

https://na3.salesforce.com/a0350000006VljmAAC

copy the 15-18 character id and append it to the url for your apex page, for example:

https://na3.salesforce.com/apex/myvfpage?id=a0350000006VljmAAC

and the tag you are using earlier was correct


<apex:outputfield value="{!Item.Item_Code__c}"/>


Is this what you were looking to accomplish Olivia?



Sameer
Olivia FordeOlivia Forde
Hi Sameer
Yes I have tried that - the Item Code is visible when I open the Item but whi I hit Edit (which is my VF page) it displays only the label. I have even copied the code from the URL onto the Edit page but with the same result
Sameer Tyagi SFDCSameer Tyagi SFDC
Hi Olivia,

Can you please share your Controller code with us?

Because you are using two objects

editItem
and
item

and try this 

<apex:outputfield value="{!EditItem.Item_Code__c}"/>

With the URL of record on page

Sameer
 
This was selected as the best answer
Olivia FordeOlivia Forde
Hi Sameer
Thats the solution - wrong controller. Many thanks :)