0

I have a requirement to conditionally style the font for a single inputfield based on the User's profile, however, below statement does not appear to be rendering properly. Is this possible using native Visualforce 'style' function?

<apex:inputField value="{!PartnershipRequest__c.OverallStatus__c}" style="{$Profile.Name!='System Administrator',color:gray}"/>
2

The syntax is:

IF(condition, value_if_true, value_if_false)

What you need to fix:

  • You are missing the IF function entirely
  • You are missing quotes around your value_if_true
  • You are missing value_if_false entirely
  • You are missing the bang (!) in your merge syntax
    • Correct syntax is {!...}, not {...}

Incorrect:

"{$Profile.Name!='System Administrator',color:gray}"

Correct:

"{!IF($Profile.Name!='System Administrator','color:gray', ''}"

Note that generally, using class attributes is preferable to inline styling (styleClass for Visualforce components such as <apex:inputField>).

  • Thanks Adrian. Is the syntax exactly the same for outputField? – FWSFDC Jan 16 at 20:51
  • The syntax for the IF function never changes... – Adrian Larson Jan 16 at 20:53

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.