function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kumarrkumarr 

how to Pass values from component to controller

I have a lightning component which contains input fileds(checkbox and picklist). These fields are not related to any object. 
How can i pass the field values from component to JS controller on click of submit button??

NOTE: I cannot make use of Component.find() or aura:attribute as the fields on the component are populated through aura:iteration.
Any help would be highly appreciated.
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Ramireddy,

Can you post your component your component here
kumarrkumarr
Hi Devi Chandrika,

Here is the component code

<aura:iteration items="{!v.formElement}" var="element" indexVar="indx">
                                        
                                        <aura:if isTrue="{!element.formType=='Check Box'}">
                                            <lightning:input aura:id="{!'field'+indx}" type="checkbox" name="{!'element-'+indx}" label="{!element.formLabel}"                                                                         checked="{!element.formSelectedValue=='TRUE'}" onchange="{!c.onChnageCheck}"/>
                                        </aura:if>
                                        
                                        <aura:if isTrue="{!element.formType=='Pick List'}">                                            
                                            <lightning:select aura:id="{!'field'+indx}" name="{!'element-'+indx}" label="{!element.formLabel}" value="                                                                               {!element.formSelectedValue}" onchange="{!c.onChnageCheck}">
                                                <aura:iteration items="{!element.formDefaultPicklistValue}" var="opt">
                                                    <option text="{!opt}" value="{!opt}"/>
                                                </aura:iteration>
                                            </lightning:select>                                            
                                        </aura:if>
                                        
                                        <aura:if isTrue="{!element.formType=='Header'}">                                            
                                            <Br/> <p style="font-weight: bold; padding-bottom: 6px;">{!element.formLabel}</p>                                            
                                        </aura:if>
                                        
                                        <aura:if isTrue="{!element.formType=='Text Area'}">
                                            <aura:If isTrue="{!v.openChild}">
                                                <lightning:textarea aura:id="{!'field'+indx}" name="{!'element-'+indx}" label="{!$Label.c.CL_OptionsLongText}"                                                                    placeholder="{!$Label.c.CL_placeholder}" onchange="{!c.onChnageCheck}"/>
                                            </aura:If>
                                        </aura:if>
                                        
                                        <aura:if isTrue="{!element.formType=='Backend'}">                                            
                                            <lightning:select aura:id="{!'field'+indx}" name="{!'element-'+indx}" label="{!$Label.c.CL_SelectAcontact}" value="                                                                      {!v.selectedContact}" onchange="{!c.onChnageCheck}">
                                                <aura:iteration items="{!v.contacts}" var="contact">
                                                    <option text="{!contact.Name+' ('+contact.Email+')'}" value="{!contact.Id}"/>
                                                </aura:iteration>
                                            </lightning:select>                                            
                                        </aura:if>
                                    </aura:iteration>

NOTE : I am not able to make use of aura:id since local Ids doesnot support expressions

 
Kishore Vamsi 6Kishore Vamsi 6
Hi Ramireddy.

You can pass parameters from components to apex 

component:
var action = cmp.get("c.serverEcho");
action.setParams({ firstName : "Jennifer" });
Apex class:
 
@AuraEnabled
public static String serverEcho(String firstName) {
    return ('Hello from the server, ' + firstName);
}


 
kumarrkumarr
Hi Kishore,

How will i get the value of the field??
Because here i am not able to make use of aura:attribute