0

In my VF page I need to disable an inputField based on a boolean condition set in my controller. If I add the html-disabled option to the inputField it disables the field, regardless of what I set the value to (true or false). Only when I remove the html-disabled setting altogether, does it allow input.

<apex:inputField  html-disabled="{!IF(allowChoice, false , true)}" value="{!account.Preference__c}" html-placeholder="Select"/>

If allowChoice = true, I want the inputField to allow input (it's a picklist /dropdown). If it's false, I want to disallow selection. Problem is, regardless of what allowChoice is set to, it disables the field on the page.

1 Answer 1

2

Because, by definition, if the HTML disabled attribute exists at all, the field is disabled. It's not a boolean.

I suppose you could put two consecutive instances of <apex:inputField>, one disabled with rendered="{! !allowChoice}" and the other enabled with rendered="{!allowChoice}". That way VF will only ever render one of them at a time. Or make the read-only one an <apex:outputField>.

4
  • So how do I achieve what I'm trying to do then if I can't use this - do you have an alternative suggestion maybe please?
    – Irene
    Jun 30, 2019 at 1:20
  • I suppose you could put two consecutive instances of <apex:inputField>, one disabled with rendered="{! !allowChoice}" and the other enabled with rendered="{!allowChoice}". That way VF will only ever render one of them at a time. Or make the read-only one an <apex:outputField>.
    – Charles T
    Jun 30, 2019 at 3:40
  • I have done that - solved my problem.
    – Irene
    Jun 30, 2019 at 22:20
  • Glad to hear. I added the comment to my answer.
    – Charles T
    Jul 1, 2019 at 1:35

You must log in to answer this question.

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