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
Kishore K 43Kishore K 43 

How to get input values in ui:input

I have a iteration where i need to get input field values but I am unable to get the values
this is my cmp
 
<aura:iteration items="{!v.BundleProductWrapperItems}" var="vCWI" indexVar="index">
<ui:inputText class="slds-input" aura:id="idblp" value="{!vCWI.bundleListPrice}" change="{!c.calculateDefaultFees1}"  />
<ui:inputText class="slds-input" aura:id="idbm" value="{!vCWI.bundlemarginPrice}" change="{!c.calculateDefaultFees1}"  />
this is my JS
calculateDefaultFees1:function(component, event, helper){
        var BundleDiscount=component.find("idblp").get("v.value");
        var margin=component.find("idbm").get("v.value");

    }


 
Jeffrey CheungJeffrey Cheung

component.get("v.BundleProductWrapperItems") 

The values are inside the array.

Kishore K 43Kishore K 43

Jeff, 

I am populating records aswell from the database. 
If there are 5 rows and If user wants to change the values of 2 row that should take only 2nd row value and calculate and display in the same row element.

Kishore K 43Kishore K 43
basically what i need to do is 
var total = BundleDiscount * margin ;
I need to set the total in another textbox which is in same row.
Jeffrey CheungJeffrey Cheung
Because there are multiple input ui:inputText with aura:id="idblp", you cannot find the right one in your function. What you can do is: Recalculate all rows in BundleProductWrapperItems and update it when any ui:inputText change. calculateDefaultFees1:function(component, event, helper){ component.get("v.BundleProductWrapperItems").forEach(function(item){ // do calculation here }); }
Kishore K 43Kishore K 43

Jeff, 

I am helpless on this. 

Can you help me with providing an example with this. :( 

Jeffrey CheungJeffrey Cheung
var BundleProductWrapperItems = component.get('v.BundleProductWrapperItems');
BundleProductWrapperItems.forEach(function (
            item.total = item.bundleListPrice * item.bundlemarginPrice;
});

component.set('v.BundleProductWrapperItems ', BundleProductWrapperItems );

Put it inside calculateDefaultFees1()
Kishore K 43Kishore K 43
Failed to save s360_Product_ServicesListController.js: 0Ad12000000kAYI: org.auraframework.util.json.JsonStreamReader$JsonStreamParseException: Expected ',' or '}', got FUNCTION_ARGS_END [179, 2]: 'function(component, event, helper) { var BundleProductWrapperItems = component.get('v.BundleProductWrapperItems'); BundleProductWrapperItems.forEach(function ( item.total = item.bundleListPrice * item.bundlemarginPrice; }': Source

 
Jeffrey CheungJeffrey Cheung
Opps I miss sth in my code, should be function(item)
 
var BundleProductWrapperItems = component.get('v.BundleProductWrapperItems');
BundleProductWrapperItems.forEach(function(item) (
            item.total = item.bundleListPrice * item.bundlemarginPrice;
});

component.set('v.BundleProductWrapperItems ', BundleProductWrapperItems );

 
Kishore K 43Kishore K 43

If you see the pic,
billing fee and margin fee are autocalculated. 

but there are 0's in the fields user will fill the change the value from 0 to any other interger that Billing and margin fee needs to be calculated. 
User-added image

Kishore K 43Kishore K 43

No jeff, 

i get error while saving
 

Failed to save s360_Product_ServicesListController.js: 0Ad12000000kAYI: org.auraframework.util.json.JsonStreamReader$JsonStreamParseException: Expected ',' or '}', got FUNCTION_ARGS_END [180, 2]: 'function(component, event, helper) { var BundleProductWrapperItems = component.get('v.BundleProductWrapperItems'); BundleProductWrapperItems.forEach(function(item) ( item.total = item.bundleListPrice * item.bundlemarginPrice; }': Source
Kishore K 43Kishore K 43
as you said 
i am trying to put this inside calculateDefaultFees1
 
calculateDefaultFees1:function(component, event, helper){
      
 var BundleProductWrapperItems = component.get('v.BundleProductWrapperItems');
BundleProductWrapperItems.forEach(function(item) (
            item.total = item.bundleListPrice * item.bundlemarginPrice;
});

component.set('v.BundleProductWrapperItems ', BundleProductWrapperItems );

    }

 
Jeffrey CheungJeffrey Cheung
The error you are getting means there is a parsing error in your code. Probably the number of braces and curly braces dont match. Your editor should have told you about this error.
 
calculateDefaultFees1: function (component, event, helper) {

        var BundleProductWrapperItems = component.get('v.BundleProductWrapperItems');
        BundleProductWrapperItems.forEach(function (item) {
            item.total = item.bundleListPrice * item.bundlemarginPrice;
        });

        component.set('v.BundleProductWrapperItems', BundleProductWrapperItems);

    }