You need to sign in to do that
Don't have an account?
Ananthanarayanan Nemmara
Date not auto-populating
Hi All,
I am trying to auto-populate the date feild in a lightning component which seemed to be working fine few days before but now its not working. Don't know is it because of any release.
Please find below the code:
component:
<aura:component controller="customLookupController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:attribute name="fromSalesperson" type="sObject" default=""/>
<aura:attribute name="toSalesperson" type="sObject" default=""/>
<aura:attribute name="searchResult" type="List" default="{}"/>
<aura:attribute name="request" type="date"/>
<aura:attribute name="effective" type="date" />
<aura:handler name="init" action="{!c.init}" value="{!this}" />
<table>
<tr>
<td style="padding:15px"><c:customLookup objectAPIName="user" IconName="standard:user" selectedRecord="{!v.fromSalesperson}" label="From Salesperson" /></td>
<td style="padding:15px"><c:customLookup objectAPIName="user" IconName="standard:user" selectedRecord="{!v.toSalesperson}" label="To Salesperson" /></td>
</tr>
<tr>
<td style="padding:15px"><lightning:input aura:id="effectiveDate" value="{!v.effective}" name="effectiveDateOfChange" type="date" label="Effective Date of Change" required="true"/></td>
<td style="padding:15px"><lightning:input aura:id="requestDate" value="{!v.request}" name="dateRequested" type="date" label="Date Requested" required="true" class="slds-hidden" /></td>
</tr>
controller:
{
init : function(component,event,helper) {
var today = new Date();
var monthDigit = today.getMonth() + 1;
if (monthDigit <= 9) {
monthDigit = '0' + monthDigit;
}
component.set('v.request', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());
component.set('v.effective', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());
},
The date was auto-populating last week.
Can someone please help me with this.
Regards,
Anand
I am trying to auto-populate the date feild in a lightning component which seemed to be working fine few days before but now its not working. Don't know is it because of any release.
Please find below the code:
component:
<aura:component controller="customLookupController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:attribute name="fromSalesperson" type="sObject" default=""/>
<aura:attribute name="toSalesperson" type="sObject" default=""/>
<aura:attribute name="searchResult" type="List" default="{}"/>
<aura:attribute name="request" type="date"/>
<aura:attribute name="effective" type="date" />
<aura:handler name="init" action="{!c.init}" value="{!this}" />
<table>
<tr>
<td style="padding:15px"><c:customLookup objectAPIName="user" IconName="standard:user" selectedRecord="{!v.fromSalesperson}" label="From Salesperson" /></td>
<td style="padding:15px"><c:customLookup objectAPIName="user" IconName="standard:user" selectedRecord="{!v.toSalesperson}" label="To Salesperson" /></td>
</tr>
<tr>
<td style="padding:15px"><lightning:input aura:id="effectiveDate" value="{!v.effective}" name="effectiveDateOfChange" type="date" label="Effective Date of Change" required="true"/></td>
<td style="padding:15px"><lightning:input aura:id="requestDate" value="{!v.request}" name="dateRequested" type="date" label="Date Requested" required="true" class="slds-hidden" /></td>
</tr>
controller:
{
init : function(component,event,helper) {
var today = new Date();
var monthDigit = today.getMonth() + 1;
if (monthDigit <= 9) {
monthDigit = '0' + monthDigit;
}
component.set('v.request', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());
component.set('v.effective', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());
},
The date was auto-populating last week.
Can someone please help me with this.
Regards,
Anand
I have resolved this issue. Added the below code:
init : function(component, event, helper) {
var today = new Date();
var monthDigit = today.getMonth()+1;
var daydate= today.getDate();
if(daydate<=9)
{
daydate = '0' + daydate;
}
if (monthDigit <= 9) {
monthDigit = '0' + monthDigit;
}
var finaldate = today.getFullYear() + "-" + monthDigit + "-" + daydate;
component.set("v.request", finaldate);
component.set("v.effective", finaldate);
Regards,
Anand
All Answers
I have resolved this issue. Added the below code:
init : function(component, event, helper) {
var today = new Date();
var monthDigit = today.getMonth()+1;
var daydate= today.getDate();
if(daydate<=9)
{
daydate = '0' + daydate;
}
if (monthDigit <= 9) {
monthDigit = '0' + monthDigit;
}
var finaldate = today.getFullYear() + "-" + monthDigit + "-" + daydate;
component.set("v.request", finaldate);
component.set("v.effective", finaldate);
Regards,
Anand