I would like an input to be conditionally read-only, but I cannot find a way to make a boolean HTML attribute like html-readonly conditional within VisualForce. I am avoiding Javascript to remove the attribute mainly because I am new to VisualForce and want to see what I can do with pure VisualForce (minimal JS).

I can't use:

<apex:inputText html-readonly="{!makeItReadOnly}" value="{!foo}"/>

Because browsers evaluate any value (including false) for a boolean attribute as true.

My current work-around isn't particularly clean (though accomplishes my goal):

<apex:inputText rendered="{!makeItReadOnly}" value="{!foo}"/>
<apex:inputText html-readonly="true" rendered="{!!makeItReadOnly}" value="{foo}"/>

1 Answer 1


For normal apex:inputText fields, use the disabled attribute:

<apex:inputText disabled="{!makeItReadOnly}" value="{!foo}"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.