+ Start a Discussion
Sujendran Sundarraj 8Sujendran Sundarraj 8 

$A.localizationService.formatDate doesnot set the proper value to lightning:inputfield

Hello, 
I have an issue with Lightning:inputfield with date datatype. I want to autopopulate the close date value i.e 90 days from today. 
to acheive this I have used $A.localicationService.formatDate(mydate);
it shows the correct date in UI but it dont set that date properly in the field. 
Any idea is appreciated. 
Thank you. 
 
SwethaSwetha (Salesforce Developers) 
HI Sujendran,
What is the value you are passing? Does the approach suggested in https://salesforce.stackexchange.com/questions/266502/localizationservice-formatdatetime-method-is-not-displaying-correct-time-in-euro work for your scenario?

If this information helps, please mark the answer as best.Thank you
Sujendran Sundarraj 8Sujendran Sundarraj 8
Hi Swetha, 
Thank you for your reply, my business requirement is close date should be autopopulated with today()+90 days. and if  the user wants to change it, they can change to any dates
my Js controller:
var result = new Date();
result.setDate(result.getDate() + 90);
var today = $A.localizationService.formatDate(result);
                    console.log('today-->'+today);
              component.set("v.Opportunity",{
                             'SObjectType': 'Opportunity',
                             'Type': 'Add to Existing/Upgrade',
                             'StageName': '1 Qualify',
                             'ForecastCategoryName': 'Funnel',
                             'Probability': '20',
                             'CloseDate':today,
                             'Keep_Manual_Primary_Flag__c': false
                             });
in the screen, I could see the value in the lightning:inputfield as apr 5,2021 but the problem is if I click inside that date field and if I didnot change any value then it is throwing an validation error: "Your entry doesnot match the allowed format MMM d, YYYY." 
instead of using $A.localizationService, if I use new Date(today) in my Js. it is not showing the value in the inputfield screen but the value is assigned to that field I could see it through console.log
Thank you.