0

I have this simple function which can detect the theme of the UI. It detects as we expect like Theme3 and Them4d, however both Theme3 and Them4d I am getting the same alert "I am inside Classic". I wonder where the things went wrong. Callback result says Theme4d, but alert is showing 'I am inside Classic'.

    ({
        createRecordForEmployee: function(component, event, helper) {  

            var action = component.get("c.getUIThemeDescription");
            action.setCallback(this, function(a) {            
                alert(a.getReturnValue());
                if(a.getReturnValue()=='Theme3' ||'Theme2'){               
                    alert('I am inside Classic');               
                }else if(a.getReturnValue()=='Theme4d'){               
                    alert('I am inside LEX');               
                }else if(a.getReturnValue()=='Theme4t'){
                    alert('I am inside S1');
                }
            });
            $A.enqueueAction(action);
        }
})

enter image description here

enter image description here

1 Answer 1

1

Your JavaScript is incorrect. Without a comparison operator, such as "==", a String simply becomes a "truthy" value. For example, you'd have the same effect if you'd wrote this:

if("Theme2d") {
  alert("I am a truthy value");
}

Instead, use a switch, or make sure you type out the comparison fully.

switch(a.getReturnValue()) {
    case "Theme3":
    case "Theme2": alert("I am in Classic"); break;
    case "Theme4d": alert("I am in LEX"); break;
    case "Theme4t": alert("I am in S1"); break;
    default: alert("I have no idea where I am.");
}

if(a.getReturnValue()=='Theme3' || a.getReturnValue() == 'Theme2'){               
    alert('I am inside Classic');               
}else if(a.getReturnValue()=='Theme4d'){               
    alert('I am inside LEX');               
}else if(a.getReturnValue()=='Theme4t'){
    alert('I am inside S1');
}
0

You must log in to answer this question.

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