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
chip5chip5 

setting a date field to null in a lightning component attribute (Lightning Components Basics trail)

In the Lightning Components Basics trail, you create a component which includes an Expense__c attribute that has a Date field called Date__c.
<aura:attribute name="newExpense" type="Expense__c"
     default="{ 'sobjectType': 'Expense__c',
                    'Name': '',
                    'Amount__c': 0,
                    'Client__c': '',
                    'Date__c': '',
                    'Reimbursed__c': false }"/>

The problem is that assigning '' or null to Date__c is producing this error in the console:

<lightning:formattedDateTime> the value attribute accepts either a Date object, a timestamp, or a valid ISO8601 formatted string with timezone  offset. but we are getting the value "null" instead.
formattedDateTime.js:formatted:31

The error happens on page load when the default value is being loaded for newExpense. For initialization, it's not an issue because the date UI element is defaulting to blank anyway, the problem is later when I want to set the date to blank from javascript and I get the same error.
Best Answer chosen by chip5
chip5chip5
nevermind, the message about date formats is just a warning, not an error. The reason my update wasn't happening was because of the fact that component events only go up the hierarchy. I switched to an application event and it worked.