You need to sign in to do that
Don't have an account?
Akash 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:
controller:
Apex:
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; } }
In my case it is not saving the record but showing me alert 'nothing'.
In your controller, try to log after ou before your alert("nothing") the server side response: 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.