I'm trying to render a readonly checkbox with a negated boolean value from my model.
Salesforce won't let you do this:
<apex:inputCheckbox disabled='true' value='{! !model.myBoolean}' />
i guess this is just meant for model binding
Or this:
<apex:inputCheckbox disabled="true" selected="{! !model.myBoolean}" />
So my next thought was fine, I'll just use a standard HTML input:
<input type="checkbox" disabled="true" {!if(model.myBoolean,'','checked')}" />
However, this apparently doesn't compile.
So short of dirtying up my model by creating a new getter to just negate this value (the view should NOT dictate whats in you're model!!!), is there anything else I can do?
Best Answer
Save yourself some trouble and enlist the help of jQuery:
The problem you are having is that HTML does not care what the value of
checked
is, as long as it is present on the element it will be displayed as checked.Visualforce will not allow you to compile unless you have values associated with each attribute, this is why your
IF
merge would not compileAlso, the
selected
attribute of theinputCheckbox
does not allow you to use dynamic value. Another you thought it was going to be easy but SF quirk got in the waySo you are in a catch 22. jQuery/JS is easiest or render based on value using panels:
Simplified version
this is implementation simplified with add ONE line