1

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.

3

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}"/>
  • 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 Sep 23 '17 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> – Syed Moosa Nazir TN Sep 27 '17 at 0:08
2

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}"/>
  • 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 Sep 23 '17 at 19:04

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.