i am not able to pass the default value of drop down list to my controller. When i click on submit button without changing the drop down list value (ie. index 0 is set as default value), add function of controller is getting called where i am displaying the drop down list value. I am getting "undefined" instead of "abc". Please suggest what is missing in the code.
Below is my code:
Component:
<aura:attribute name="it" type="string[]" />
<!-- List -->
<div id="">
<div class="list-group">
<div class="list-group-item">
<ui:button press="{!c.DetailPage}" class="btn btn-success pull-right" >plus</ui:button>
<h4 class="list-group-item-heading">test</h4>
</div>
</div>
</div>
<!-- Screen opens when {!c.DetailPage} -->
<div class="container">
<form aura:id="frm1">
<fieldset>
<ui:inputSelect aura:id="P">
<aura:iteration items="{!v.it}" var="item" indexVar="index">
<aura:if isTrue="{!index ==0}" >
<ui:inputSelectOption text="{!item}" value="true"/>
<aura:set attribute="else">
<ui:inputSelectOption text="{!item}"/>
</aura:set>
</aura:if>
</aura:iteration>
</ui:inputSelect>
...
<ui:button press="{!c.add}" class="btn btn-primary pull-right">Submit</ui:button>
</fieldset>
</form>
</div>
Client side controller:
DetailPage : function(component, event, helper) {
helper.checkdefaultvalue(component, event, helper);
},
add : function(component, event, helper) {
var defaultDropdown = component.find("P").get("v.value");
console.log('p..'+defaultDropdown);
// here p value is coming as undefined instead of "abc"
}
Helper :
checkdefaultvalue:function(component, event, helper){
var action = component.get("c.temp");
action.setCallback(this, function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
var res = response.getReturnValue();
component.set("v.it", res);
console.log("it optiom: "+res);
}else{console.log("failure...");}
});
$A.enqueueAction(action);
},
Apex class:
@AuraEnabled
public static List<String> temp() {
List<string> temp1 = new List<string>();
temp1.add('abc');
temp1.add('def');
temp1.add('ghi');
System.debug('temp1...'+temp1);
return temp1;
}
component.find("P").get("v.value");
where is P