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
Matthew Harris 40Matthew Harris 40 

How do I add fieldinput values to an object in Lightning?

m working on a component where a table is generated by data entered into 3 input fields (Year, Make and Model). I have a function where the user's inputs are assigned to their corresponding variable which are then to be added to an object type attribute, GarageItems. This would then be used to populate the datatable in my component. How could I do this?

 Here is my Component
<aura:component>

       <aura:handler name="init" value="{! this }" action="{! c.init }"/>

   
       <aura:attribute name="YearInput" type="Integer"/>
       <lightning:input aura:id="IdYear" name="CarYear" placeholder="Please type the Car's Year" value="{! v.YearInput }" />
           
       <aura:attribute name="MakeInput" type="String"/>
       <lightning:input aura:id="IdMake" name="CarMake" placeholder="Please type the Car's Make" value="{! v.MakeInput }" />
       
       <aura:attribute name="ModelInput" type="String"/>
       <lightning:input aura:id="IdModel" name="CarModel" placeholder="Please type the Car's Model" value="{! v.ModelInput }" />
   
   
       <aura:attribute name="GarageItems" type="Object"/>
       <aura:attribute name="Columns" type="List"/>

       
       <div style = "height: 300px">
           <lightning:datatable
                   key-field="id"
                   data="{!v.GarageItems}"
                   columns="{!v.Columns}">
           </lightning:datatable>
       </div>

   
   <lightning:button variant="brand" label="Submit" title="Submit action" onclick="{! c.SubmitData }" />
   <lightning:button variant="brand" label="Clear Fields" title="Clear action" onclick="{! c.ClearFields }" />

</aura:component>

Here is my Controller
({
    init: function (cmp, event, helper) 
        {
             cmp.set('v.Columns', 
                     [
                         {label: 'Year', fieldName: 'CarYear', type: 'integer'},
                         {label: 'Make', fieldName: 'CarMake', type: 'text'},
                         {label: 'Model', fieldName: 'CarModel', type: 'text'}
                     ]);
        },
    
    
    SubmitData : function(component, event, helper) 
        {
            var Year = component.get("v.YearInput"); 
            var Make = component.get("v.MakeInput"); 
            var Model = component.get("v.ModelInput"); 
            
            if ((Year != "")&&(Make != "")&&(Model != ""))
                
                {
//take year.make.model and add to GarageItems; **This is where I'm having the issue**
}
            
            else
            {
                return null;
            }
            
        },
    
     ClearFields : function(component, event, helper)
        {
            component.set("v.YearInput", "");
            component.set("v.MakeInput", "");
            component.set("v.ModelInput", "");
        }
    
    
})