How do I make apex:inputField disabled Or readOnly

  • I have a parent account field with a magnifying glass on the right side of it. I need to users to only click on the magnifier glass and search for the parent and not type in the field . Most of the time they spell it wrong and they wont click on the magnify glass and they get error.

     <apex:pageBlockSectionItem rendered="{!IF($UserRole.Name =='Channel Manager' || $UserRole.Name == 'Outside Sales Director' ||$UserRole.Name == 'Salesforce Administrator', true , false)}" >
            <apex:outputLabel value="Parent Account" for="acctparent" />
            <apex:inputField id="acctparent"  styleClass="acctparent" value="{!account.ParentId}"  />
      </apex:pageBlockSectionItem>
    
                <apex:pageBlockSectionItem >
    

    I have tried javascript and didnt work

    $("input[id*='acctParent']").attr("disabled","disabled");
    

    or

    $("input[id*='acctParent']").attr("disabled","true");
    

    or

    $("input[id*='acctParent']").prop('readonly', true);
    

    i tired

    <apex:outputPanel rendered="{!onOff}">
    <apex:inputField value="{!someField}"/>
    

    didnt work

    I tried

  • Metawaa

    Metawaa Correct answer

    5 years ago

    I found a solution i guess I can use this

    html-disabled="true"

    <apex:inputField id="acctparent"  styleClass="acctparent" value="{!account.ParentId}"  html-disabled="true"  />
    

    and as a secondary way if you have onchange on your button, use the following

    onfocus="this.blur" onkeypress="this.blur()"  onchange="getSobjectList()"
    

    If you would have read the comments your issue was simply a case sensitive issue. your jQuery would have worked had you used `acc` **p** `arent` with proper placement

    the one on Mark Pond does not seem to work while html-disabled="true" is definitely the answer !!..Thanks Meta

    this answer is rather misleading. the `disabled` attribute is not a boolean. if you set `disabled="false"` it will still be disabled

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used