0

I have two fields in an object, I need choose only one of these fields. I tried using:

    <apex:inputField label="{!If(lang=='en' ,'Event type','Tipo de evento')}" value="{!If(lang=='en', nl.Event_type__c, nl.Tipo_de_evento__c)}" id="idEvento" />

But it doesn't work.

  • 2
    Are you sure you can use IF statements when binding to a field? I don't think so. Why don't you use two inputText with a "rendered" property? – Sebastian Kessel Jul 12 '17 at 0:22
0

The method you've tried won't work; expressions end up causing the binding to be read-only. A better choice would be to use a var, and bind using dynamic binding.

<apex:var name="eventField" 
    value="{!IF(lang='en', 'Event_Type__c', 'Tipo_de_evento__c')}" />
<apex:inputField label="{!If(lang=='en' ,'Event type','Tipo de evento')}" 
    value="{!nl[eventField]}" id="idEvento" />

The "bracket notation" ([field]) is used to dynamically reference a field or object. Note that the variable itself must use string values for this to work.

  • I don't understand why if I using the field name "Tipo_de_evento__c" is right, but if I use the field name Event_Type__c I got a session error, it's public page. Thanks a lot – netovs Jul 12 '17 at 16:03
  • This <apex:var name="eventField" value="{!IF(lang='en', 'Event_Type__c', 'Tipo_de_evento__c')}" /> <apex:inputField label="{!If(lang=='en' ,'Event type','Tipo de evento')}" value="{!nl[eventField]}" id="idEvento" /> Was gold for me, thans a lot, thanks a lot really thanks every body. The final error was the "Dependent Fields" fixed the dependences you code save me today, thanks. – netovs Jul 12 '17 at 16:33

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.