I have a visual force page where I want to disable the user from editing some of the fields on it. I used the css class attribute to identify these fields.

Input Textboxes were disabled successfully using this approach, but the lookup fields are still accessible.

How can I disable the lookup fields so that the user is unable to make any changes?

Declaration of Field:

<apex:inputField styleClass="makeSelectReadOnly" value="{!Opportunity.AccountId}" required="true"/>

JQuery to disable the field:


Screenshot: Screenshot of VF page

  • use the same jquery to hide the lookup icon element...... – Eric Nov 1 '16 at 16:17
  • This looks promising. I just need to find out where the element is. – abhi Nov 1 '16 at 16:19
  • jQuery(".lookupIcon").hide(); works, but also hides the icon for the Opportunity Owner which needs to stay. :) – abhi Nov 1 '16 at 16:23
  • 1
    If you are ok with just showing the account name (without the disabled input), just use apex:outputField – willard Nov 1 '16 at 16:24
  • 1
    if you really want to use jquery, try jQuery('.makeSelectReadOnly').next().click(function(e){e.preventDefault();}) – willard Nov 1 '16 at 16:29

The JQeury doesn't handle the lookup button..

In case it is always disable consider using instead : apx:outputField

If it depend on criteria you can add both input & output but show only 1 of them:

<apex:inputField styleClass="makeSelectReadOnly" value="{!Opportunity.AccountId}" required="true" rendered="{!openForEdit==true}"/>
<apex:outputield styleClass="makeSelectReadOnly" value="{!Opportunity.AccountId}" rendered="{!openForEdit==false}"/>
| improve this answer | |
  • This is what I have done with all the dateFields on the page and I was hoping to avoid this. – abhi Nov 1 '16 at 16:24
  • @SantanuBoral <apex:outputField value="{!Opportunity.AccountId}"/> works just fine for me in a visualforce page being displayed on one of my standard layouts. – Derek F Nov 1 '16 at 16:38
  • 1
    Gotta agree with going with standard functionality in this case. This is exactly what the <apex:output*> components were meant to do. +1 from me. – Derek F Nov 1 '16 at 16:40
  • Again, you can use only <apex:outputField... if it's always should be disabled. – Liron C Nov 1 '16 at 16:48
  • I had to do this in order to make this work the way I wanted. I am now hiding / showing the field or text depending on the view mode. – abhi Nov 2 '16 at 13:50

My thoughts on this would be to use the <apex:outputField /> tag on occasions that you don't want the user to be able to edit the field.

<apex:inputField rendered="{!NOT(makeSelectReadOnly)}" value="{!Opportunity.AccountId}" required="true"/>
<apex:outputField rendered="{!makeSelectReadOnly}" value="{!Opportunity.AccountId}" required="true"/>

Where makeSelectReadOnly is a boolean variable populated in the apex class.

Just know that if you mark it as required="true" and the field has no value, it will cause the page to error.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.