You need to sign in to do that
Don't have an account?
How to save lightning:input type="datetime-local" to database?
It seems that there is a bug with lightning:input type="datetime-local" tag. When I add this tag in my component, thenchoose a date and time using the date time selector and try to save the record to database, apex is not able to take the value? Any pointers on how to save this value to a date time field present on an object. Below is the sample code I am trying to implement:
dateTimeLocal.cmp
DateTimeLocalCtrl.apxc
dateTimeLocal.cmp
<aura:component controller="DateTimeLocalCtrl"> <aura:attribute name="lead" type="Lead" default="{'sobjectType':'Lead','id':'00Q9000001BtwNE'}"/> <lightning:input type="datetime-local" label="Start" name="Start" value="{!v.lead.Start__c}"/> <lightning:button label="Save" iconName="utility:save" onclick="{!c.doSave}"/> </aura:component>dateTimeLocalController.js
({ doSave : function(component, event, helper) { var action = component.get("c.upsertLead"); var lead = component.get("v.lead"); console.log("*****Date: "+component.get("v.lead.Start__c")); // set param to method action.setParams({ 'ld': lead }); // set a callBack action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { console.log("*****Success"); }else{ console.log("*****Failure"); } }); // enqueue the Action $A.enqueueAction(action); } })
DateTimeLocalCtrl.apxc
public class DateTimeLocalCtrl { @AuraEnabled public static Lead upsertLead(Lead ld){ upsert ld; return ld; } }
sara morgan provied a workaround for it please check below link :
https://saramorgan.net/2017/10/01/workaround-for-problem-with-lightninginput-and-datetime-local/
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks