3

I'm getting the input using <apex:inputField> (must be inputField rather than inputText to enforce FLS). The disabled attribute is not supported for the <apex:inputField> tag, so I'm trying to use an html passthrough attribute from the custom controller:

html-disabled="{!booleanVariable}"`

Based on the boolean value I'm planning to enable and disable the field. However, when I try to use html-disabled="true" or html-disabled="true" or html-disabled="" every values always make this input field disabled.

What am I doing wrong here?

2 Answers 2

3

You could change your design to display disabled values.

Rather than disabling the apex:inputField better to use apex:outputField using proper rendered condition.

Most of the scenarios like disabling a inputField lookup normally not possible. So, this kind of design will solve the purpose.

Here is an example of lookup field:

<apex:panelGroup id="theGroup" rendered="{!isEnabled}">
    <apex:inputField id="AccountId" value="{!opportunityObj.AccountId}"/>
</apex:panelGroup>

<apex:panelGroup id="theGroup2" rendered="{!NOT(isEnabled)}">
    <apex:inputText value="{!accountObj.Name}" disabled="true"/>
</apex:panelGroup>
3
  • Thanks a lot for the response. Hope this helps me to choose a different option. Commented Jun 28, 2017 at 1:26
  • Sure I'll do that. How about below. It works as expected, but do you see anyother implication on this. <apex:inputField value="{!todo.Remainder_Email__c}" rendered="{!show}" /> <apex:inputField value="{!todo.Remainder_Email__c}" rendered="{!!show}" html-disabled="true"/> Commented Jun 28, 2017 at 1:50
  • see, some inputField satisfies properly, like text, email, phone types, but some others could create issues, so idea is, whatever supports properly you could leverage html-disabled="true" otherwise, take the above approach Commented Jun 28, 2017 at 2:01
3

Unfortunately, any value for the disabled attribute will disable the field.

You can wrap the input field in a conditionally-rendered <apex:outputPanel>. Do something like this so that only one inputField is shown at a time.

<apex:outputPanel rendered="{! booleanValue}">
    <apex:inputField html-disabled="true" /> (or maybe apex:outputField here)
</apex:outputPanel>
<apex:outputPanel rendered="{!!booleanValue}">
    <apex:inputField />
</apex:outputPanel>

Similar to this question.

1
  • 1
    Thanks a lot for the response. Hope this helps me to choose a different option. Commented Jun 28, 2017 at 1:26

You must log in to answer this question.

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