I'm getting some strange results trying to do a simple demo of lightning:radioGroup
using aura:if
to conditionally render components. I've added a controller method to show the weirdness.
Component:
<aura:component implements="flexipage:availableForAllPageTypes">
<aura:attribute name="opts" type="Map[]"
default="[
{'label': 'apples', 'value': 'a'},
{'label': 'oranges', 'value': 'o'}
]"/>
<aura:attribute name="value" type="String" default="o"/>
<lightning:radioGroup type="button"
aura:id="mygroup" onchange="{!c.myAction}"
name="radioButtonGroup"
label="Radio Button Group"
options="{!v.opts}"
value="{!v.value}"
required="true" />
<aura:if isTrue="{!v.value=='a'}">
<p>Option 1 is selected (simple).</p>
</aura:if>
<aura:if isTrue="{!v.value=='o'}">
<p>Option 2 is selected (simple).</p>
</aura:if>
<aura:if isTrue="{!(''+v.value)=='a'}">
<p>Option 1 is selected (coerced).</p>
</aura:if>
<aura:if isTrue="{!(''+v.value)=='o'}">
<p>Option 2 is selected (coerced).</p>
</aura:if>
</aura:component>
Controller:
({
myAction : function(c, event, helper) {
var value = c.get('v.value');
console.log(value);
console.log(value+'');
console.log(value == 'a');
}
})
So basically, on initial load with a default value of "o", it starts on oranges (option 2) and I get both Option 2 paragraphs rendering. Once I flip the button, I only get the "coerced" Option 2 paragraphs.
When I monitor in the browser's Developer Console, I see:
Proxy { <target>: Array[1], <handler>: Object }
WARNING: Unsupported a method: Symbol(Symbol.toPrimitive). Returning undefined
a
WARNING: Unsupported a method: Symbol(Symbol.toPrimitive). Returning undefined
true
So even though the selected radio option maps to the simple string "a", the result retrieved from it is still a proxied object.
In the markup this has the totally unintuitive effect of failing to meet an equality test with the string "a" in an aura:if
statement. However, if I coerce the value to a string in the expression syntax by adding it to an empty string, the equality test now works.
In the controller this seems to still produce normally expected results (the proxy object passes an equality test with "a") aside from the console.log
result. However, it does throw that strange error message.
FWIW: I already tried initializing opts
in the controller instead of the view and I get the same result.
Is this a new and odd behaviour? Bug-report-worthy?