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
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA 

how to copy values to field in aura:iteration dynamically

Hi All,

Here I'm trying to copy values from the output text table data to respect of their field which are price and Qty 

Please take look at the below picture for an idea.

User-added image

Here I'm using Inside two aura: iterations and I'm those price and qty from the different objects instead of entering the user he will just click and copy the values.

Please take a look at the below coding What I have return:
 
<div class="slds-section__content" id=" OrderLineItemsId">
                <aura:iteration items="{!v.OrderItems}" var="item">
                    <table><tr>
                        <td><lightning:input label="S.No" value="" />  </td>
                        <td>
                        <lightning:input label="P/N" value="{!item.Name}" /> 
                        </td>
                        <td> <lightning:input label="P/N" value="{!item.client_Pn__c}" /> </td>

                        <td> <lightning:input label="Description" value="{!item.Description__c}" /> </td>
                        <td> <lightning:input label="Prod" value="{!item.Family__c}" /> </td>
                        <td> <lightning:input type="Date" label="Shipping Date" value="{!item.Confirmed_Shipping_Date__c}" /> </td>
                      <td> 
                            <aura:iteration items="{!item.Batch}" var="ba">
                                <table border="1" id="thispa">
                                    <tr><th> Price </th>
                                        <th> Qty </th>
                                    </tr>
                                	<tr>
                                         <td> <ui:outputText title="Price" aura:id="baprice" value="{!ba.Unit_Price__c}"/>  </td>
                                         <td>  <ui:outputText title="Qty" aura:id="baqty" value="{!ba.Asked_Qty__c}" />  </td>
                                         <td> <ui:inputRadio aura:id="r0" name="select" label="Action" change="{!c.CopyValues}"/> </td>
                                      
                                    </tr>
                                </table>    
                             </aura:iteration>
                        </td>
                        <td> <lightning:input label="Qty" value="{!item.Quantity__c}" /> </td>
                        <td> <lightning:input label="Unit Pice" value="{!item.Price__c}" /> </td>
                         
                        </tr>
                        -------------------------------------------------------------------------------------------------
                    </table>
                 </aura:iteration>    
            </div>
 
Controller:

 CopyValues: function(component, event, helper) { 
       console.log("entered");
  
       var pricem=event.getSource();
       var selectedItemNew=document.getElementById(pricem).value();
       console.log(pricem.get("v.value"));   
       var table = document.getElementsById("thispa");  
         console.log(table);       
      }

Here I'm not able to get anything


 
Ajay K DubediAjay K Dubedi
Hi,
I have understood your question and find a solution below. You should make some changes to your code.

Firstly you have to assign an attribute of boolean type.
<aura:attribute name="radioButtonChosen" type="boolean" default="false"/>


<div class="slds-section__content" id=" OrderLineItemsId">
                <aura:iteration items="{!v.OrderItems}" var="item">
                    <table><tr>
                        <td><lightning:input label="S.No" value="" />  </td>
                        <td>
                        <lightning:input label="P/N" value="{!item.Name}" /> 
                        </td>
                        <td> <lightning:input label="P/N" value="{!item.client_Pn__c}" /> </td>

                        <td> <lightning:input label="Description" value="{!item.Description__c}" /> </td>
                        <td> <lightning:input label="Prod" value="{!item.Family__c}" /> </td>
                        <td> <lightning:input type="Date" label="Shipping Date" value="{!item.Confirmed_Shipping_Date__c}" /> </td>
                      <td> 
                            <aura:iteration items="{!item.Batch}" var="ba">
                                <table border="1" id="thispa">
                                    <tr><th> Price </th>
                                        <th> Qty </th>
                                    </tr>
                                    <tr>
                                         <td> <ui:outputText title="Price" aura:id="baprice" value="{!ba.Unit_Price__c}"/>  </td>
                                         <td>  <ui:outputText title="Qty" aura:id="baqty" value="{!ba.Asked_Qty__c}" />  </td>
                                         <td> <ui:inputRadio aura:id="r0" name="select" label="Action" change="{!c.CopyValues}"/> </td>
                                      
                                    </tr>
                                </table>    
                             </aura:iteration>
                        </td>

                  <aura:if isTrue="{!v.radioButtonChosen==true}" >
                        <td> <lightning:input label="Qty" value="{!ba.Asked_Qty__c}" /> </td>
                        <td> <lightning:input label="Unit Pice" value="{!ba.Unit_Price__c}" /> </td>
                         </aura:if >

                        </tr>
                        

                    </table>
                 </aura:iteration>    
            </div>



Controller:

 CopyValues: function(component, event, helper) { 
         
         var checkValue = c.get('v.radioButtonChosen');  
         c.set('v.radioButtonChosen' , true); 
      }


Use the above code to get the desired result.
If you are still facing any problem, feel free to ask.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA

Thanks for your reply @Ajay K Dubedi

See Actually I want to copy the values to respective fields Unit price and qty that I have shown in the above image.

You are just making the radio button that is not required when a user makes an action radio button will call the action we have to write logic for copy the data from price and qty to Unite price input field and qty 

Price ----- Unit price

Qty----Qty

NOTE: Per each row, we will have more than two price and qty actual values should copy to the respective fields.

Let's try