I am trying to set a value of an attribute via a ui:inputRadio component and an onchange listener. However, the component is not behaving like I expected it to.
TestApp.app
<aura:application >
<ltng:require scripts="{!$Resource.jquery}" afterScriptsLoaded="{!c.doInit}" />
<aura:attribute name="radiochoice" type="Integer" default="0"/>
<fieldset class="slds-form-element">
<label class="slds-form-element__label" for="select-01"> </label>
<div class="slds-form-element__control">
<label class="slds-radio">
<ui:inputRadio name="options" value="1" change="{!c.onGroup}"/>
<span class="slds-radio--faux"></span>
<span class="slds-form-element__label">Choice 1</span>
</label>
<label class="slds-radio">
<ui:inputRadio name="options" value="2" change="{!c.onGroup}"/>
<span class="slds-radio--faux"></span>
<span class="slds-form-element__label">Choice 2</span>
</label>
</div>
</fieldset>
<p>{!v.radiochoice}</p>
</aura:application>
TestAppController.js
({
doInit : function(cmp, event, helper) {
},
onGroup: function(cmp, evt) {
var elem = evt.getSource();
console.log(evt);
console.log(elem);
console.log(elem.get("v.body"));
console.log(elem.get("v.class"));
console.log(elem.get("v.label"));
console.log(elem.get("v.name"));
console.log(elem.get("v.text"));
console.log(elem.get("v.value"));
console.log($("input[name='options']:checked").val());
cmp.set("v.radiochoice", elem.get("v.text"));
},
})
I should be seeing a 1 in the output somewhere in the log when I run this, but instead I get
components/mynamespace/Testapp.js:13 Object {}
components/mynamespace/Testapp.js:14 Object {}
components/mynamespace/Testapp.js:15 []
components/mynamespace/Testapp.js:16 undefined
components/mynamespace/Testapp.js:17 undefined
components/mynamespace/Testapp.js:18 options
components/mynamespace/Testapp.js:19 undefined
components/mynamespace/Testapp.js:20 true
components/mynamespace/Testapp.js:21 undefined
The documentation at Aura ui:inputRadio documentation says the "text" attribute contains the input value attribute, but for some reason it returns undefined even though I specified a value for each radio button.
On a side note, the example code in the documentation does not work..
var elem = evt.getSource().getElement();
throws an exception as the object returned by calling getSource() on the event does not have a getElement function.. Even if that were fixed, the code still would not run since LockerService runs in strict mode and resultCmp is not declared before being used..