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
Akash Choudhary 17Akash Choudhary 17 

Lightning input form component not working

Hi All,

I have a lightning component on a stanalone app which is a input form for creating a new record. But somehow it is not saving the record as expected.

component:
<aura:component controller="CreateCarRecord" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="newCar" type="Car__c"
     default="{ 'sobjectType': 'Car__c',
                     'Name': '',
                     'Build_Year__c': '',
                     'Mileage__c': '',
                      'Available_For_Rent__c': '',
                   }"/>

    
    
        <lightning:layout>
            <lightning:layoutItem size="4" padding="around-small">
              <lightning:input aura:id="carField" type="text" value="{!v.newCar.Name}" Name="Name" label ="Car Name"/>
       <lightning:input aura:id="carField" type="number" name="Build Year" label="Build Year"  value="{!v.newCar.Build_Year__c}" />
                 <lightning:input aura:id="carField" type="number"  value="{!v.newCar.Mileage__c}"  Name="Mileage" label="Mileage"/>
        <lightning:input aura:id="carField" type="checkbox"  value="{!v.newCar.Available_For_Rent__c}"  Name="Available" label="Available"/>
        
        <lightning:button aura:id="carField" label="Save Car" onclick="{!c.saveCar}"/>
            </lightning:layoutItem>
            </lightning:layout>
</aura:component>

controller:
({
	saveCar :  function(component, event) {
    var newAcc = component.get("v.newCar");
    var action = component.get("c.save");
    action.setParams({ 
        "con": newAcc
    });
    action.setCallback(this, function(a) {
           var state = a.getState();
        console.log("state--" +state);
            if (state === "SUCCESS") {
                var name = a.getReturnValue();
               alert("hello from here"+name);
            }else{
                alert("nothing");
            }
        });
    $A.enqueueAction(action)
}
})

Apex:
public class CreateCarRecord {

  
    @AuraEnabled
    public static Car__c save(Car__c con)
    {
     insert con;
        return con;
    }
}

​​​​​​​​​​​​​​
dandamudidandamudi
Hi Akash, i haven't seen any issue with your code i just  try to replicate your issue with your code but everything works fine for me. can you post your issue.User-added image
dandamudidandamudi
component code:
<aura:component controller="SeTesting" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="newCar" type="Account" default="{ 'sobjectType': 'Account','Name': ''}"/>
    
        <lightning:layout>
            <lightning:layoutItem size="4" padding="around-small">
              <lightning:input aura:id="carField" type="text" value="{!v.newCar.Name}" Name="Name" label ="Car Name"/>
        <lightning:button aura:id="carField" label="Save Car" onclick="{!c.saveCar}"/>
            </lightning:layoutItem>
            </lightning:layout>
</aura:component>

 
Akash Choudhary 17Akash Choudhary 17
Hi dandamudi,
In my case it is not saving the record but showing me alert 'nothing'.
Gabriel C FerreiraGabriel C Ferreira
Hi Akash,

In your controller, try to log after ou before your alert("nothing") the server side response:
console.log(a)
Maybe you are passing a value that is incompatible with the field type.

If this helped solved your issue, please mark as the best response.

Best regards.