2

As the apex:inputField doesn't support disabled attribute (but apex:inputText does), I was using arbitrary attribute html-disabled to accomplish this. But, I was wondering if we can add a condition or boolean to arbitrary attributes. I tried something like

<apex:inputField value="{!ObjA.inputPicklist1__c}" html-disabled="{!editFlag}"/>

and the field always remained disabled regardless of the flag value. So, conditional disabling of apex:inputField is not possible this way and can only be achieved via javascript? Thanks.

2 Answers 2

4

if you don't want to use js, then you need to use two VF tags.

Assuming, you want the user to enter value and setting editFlagset to true.

And when you don't want the user to enter value, setting editFlagset to false.

You can try the below logic

<apex:inputField value="{!ObjA.inputPicklist1__c}" rendered="{!editFlag}"/>
<apex:outputField value="{!ObjA.inputPicklist1__c}" rendered="{!!editFlag}"/>
2
  • Thank you. I have used rendering at different places, but it is not an option for me in this case as the page size is fixed, hiding many fields might leave off too much empty space and also we want the viewers to be aware that these fields are part of the page.
    – Seesh
    Commented Sep 23, 2017 at 19:04
  • Hi Seesh, You could also diable all input fields by using HTML FIELDSET(not Salesforce fieldset).. Example <form> <fieldset disabled> <legend>Personalia:</legend> Name: <input type="text"><br> Email: <input type="text"><br> Date of birth: <input type="text"> </fieldset> </form> Commented Sep 27, 2017 at 0:08
3

Better to show and hide the apex:inputField based on rendered attribute.

So, when editFlag = true, you will display:

<apex:inputField value="{!ObjA.inputPicklist1__c}" html-disabled="true" rendered="{!editFlag}"/>

when editFlag = false, you will display:

<apex:inputField value="{!ObjA.inputPicklist1__c}" rendered="{!!editFlag}"/>
1
  • Thank you. I have used rendering at different places, but it is not an option for me in this case as the page size is fixed, hiding many fields might leave off too much empty space and also we want the viewers to be aware that these fields are part of the page.
    – Seesh
    Commented Sep 23, 2017 at 19:04

You must log in to answer this question.

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