3

How to show apex:inputField on the VF page with pre-defined value as just text:

In the below screenshot, the task status is shown as 'Completed', I want to do the same on the VF page that I am building:

enter image description here

I tried doing this <apex:inputField value="{!Task.Status}" html-readonly= "TRUE"/> but it shows the error :

Cannot override attribute 'readonly' on component

Any suggestions?

1 Answer 1

2

Sounds like you need an <apex:outputfield value="{!Task.Status}" />.

From the docs:

A read-only display of a label and value for a field on a Salesforce object. An component respects the attributes of the associated field, including how it should be displayed to the user. For example, if the specified component is a currency field, the appropriate currency symbol is displayed. Likewise, if the component is a lookup field or URL, the value of the field is displayed as a link.

2
  • Oh..I thought apex:outputField works only for the records which are saved in the DB already. But I just tried and it is working even if I set the value in controller but not yet saved to DB.
    – javanoob
    Commented Aug 21, 2015 at 23:54
  • Glad this worked for you. Please help the rest of the community by marking it as having answered your question.
    – Rob
    Commented Aug 21, 2015 at 23:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .