Search code examples
arraysobjectcontrollersalesforce-lightning

Can't get the Object Array into Controller Function called from the Aura Component <ui:InputNumber>


Thank you, everyone, for helping me! I am just stuck I don't know if this was the issue with Salesforce or

I am doing something wrong!!!

Here is the scenario I have enabled inline editing on the card and when the user changes the value of the Quantity, the component call the JS Controller function

It didn't get the List which I have passed as a Parameter its Nothing output is attached below,

Interesting Fact

  1. But I called the same function from somewhere else like make a checkbox and on the change called the same, I get the list of Array passed as Parameter

  2. I didn't get the List when I called it from the other than that I get all the values using component.get()

Aura Component Attributes

<aura:attribute name="item" type="Object" required="true"></aura:attribute>
<aura:attribute name="title" type="String" required="true"></aura:attribute>
<aura:attribute name="bid" type="Object[]" required="true"></aura:attribute>
<aura:attribute name="box1" type="Boolean" default="false" />
<aura:attribute name="categoriesSum" type="Object" required="true"></aura:attribute>
<aura:attribute name="quantityEditMode" type="boolean" default="false"></aura:attribute>

Component Code Calling with InputNumber Not working

   <ui:inputNumber class="slds-input " labelClass="slds-form- 
   element__label slds-form-element__label_edit slds-no-flex" 
   change ="{!c.onQuantityChange}" 
   required="true" value=" 
   {!v.item.Quantity__c}" />

Component Code Calling with CheckBox Working

<ui:inputCheckbox aura:id="checkbox1" value="v2" change="{!c.onQuantityChange}"/>

JS Controller

  onQuantityChange : function(component, event, helper){
    console.log('----Item----'+component.get('v.item')); 
    console.log('----title---'+ component.get('v.title'));
    console.log('----Bid---'+ component.get('v.bid'));
    console.log('----Box---'+ component.get('v.box1'));
    console.log('---categoriesSum--component.get('v.categoriesSum'));
    console.log('----quantityEditMode---'+ component.get('v.quantityEditMode'));

   }

Output with InputNumber enter image description here

Ouputput with Checkbox enter image description here

if you need more explanation please let me know I m stuck here for almost 7 hours and yes I have also tried the helper class it's the same scenario


Solution

  • You cannot directly change the value of a field on the object using

    value=" 
       {!v.item.Quantity__c}"
    

    Instead try saving it in an attribute like v2 (you have done that on the checkbox)

    The change from the ui:inputNumber will then make it to the controller.

    Basically this:

    <aura:attribute name="v2" type="Integer"/>
    <ui:inputNumber class="slds-input " labelClass="slds-form- 
       element__label slds-form-element__label_edit slds-no-flex" 
       change ="{!c.onQuantityChange}" 
       required="true" value=" 
       {!v.v2}" />
    

    Hope this helps.