Activity Forums Salesforce® Discussions How we can disable the lookup input field on the Salesforce visualforce page?

  • Abhinav

    Member
    August 11, 2016 at 4:16 pm

    Hi Mohit,
    Apex:inputField does not have the attribute "disabled". You may have to do this through rendering or jQuery.

    Below is the sample code for rendering :-
    Sample Code:

    Visualforce page:

    <apex:page controller="sample">

    <script type="text/javascript">

    </script>

    <apex:form >

    <apex:pageMessages />

    <apex:pageBlock >
    <apex:pageBlockSection columns="2">
    <apex:pageblockSectionItem >
    <apex:outputLabel value="Metro"/>
    </apex:pageblockSectionItem>
    <apex:pageblockSectionItem >
    <apex:inputCheckbox value="{!metro}">
    <apex:actionSupport event="onchange" reRender="a" action="{!demo}"/>
    </apex:inputCheckbox>
    </apex:pageblockSectionItem>
    <apex:pageblockSectionItem >
    <apex:outputLabel value="City"/>
    </apex:pageblockSectionItem>
    <apex:pageblockSectionItem >
    <apex:inputField value="{!city}" id="a" disabled="{!bool}"/>
    </apex:pageblockSectionItem>
    </apex:pageBlockSection>
    </apex:pageBlock>

    </apex:form>

    </apex:page>

    Apex Code:

    public class sample
    {
    public Boolean metro {get;set;}
    public Boolean city {get;set;}
    public Boolean bool {get;set;}

    public sample()
    {

    }

    public void demo()
    {
    if(metro)
    {
    bool = true;
    }
    else
    {
    bool = false;
    }
    }

    }

  • Unknown Member

    Deleted User
    October 19, 2016 at 2:47 pm

    You can actually used the "disabled" attribute by adding `html-disabled="true"` to your `apex:inputField` tag.

    Source: https://developer.salesforce.com/docs/atlas.en-us.204.0.pages.meta/pages/pages_html_features_pass_through_attributes.htm

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos