Date Picker object having issues updating

I’m trying to update my date picker with a value

Everywhere else in the code, it works. This code structure works and updates. If I add button to set the date in this exact same format, it updates and properly sets the value.

However, in this one specific block of code, the element fails to update. I’ve had similar problems with the dropdown elements before, but this is the first time the Date Picker hasn’t updated


For reference here’s the code. The comments show the values on runtime for reference. Nothing else is connected/affecting this Date Picker


 if(data.individual.dateOfBirth){ 
            console.log(data.individual.dateOfBirth); //'Fri Jan 13 2017'
            console.log(typeof data.individual.dateOfBirth); //string
            const date = new Date(data.individual.dateOfBirth);
            console.log(date); //object --> Date printed properly for default date object
            console.log(date.toDateString()); //'Fri Jan 13 2017'
            $w('#dateOfBirth').value = date; 
            //date is still blank and unaffected after this point, as if the above line does not exist
 }

Any idea why this format is not working? Again if I add this same code to a button to manually trigger the update, it works. But in this block, which runs it does not.

Hard coding a data object and using your code works for me. Maybe try that to narrow it down? Or try deleting the Date Picker element and re-adding. I’ve had that strangely work in the past.

let data = { 
       individual : { 
              dateOfBirth : 'Fri Jan 13 2017'
       }           
}
if(data.individual.dateOfBirth){ 
       console.log(data.individual.dateOfBirth); //'Fri Jan 13 2017'
       console.log(typeof data.individual.dateOfBirth); //string
       const date = new Date(data.individual.dateOfBirth);
       console.log(date); //object --> Date printed properly for default date object
       console.log(date.toDateString()); //'Fri Jan 13 2017'
       $w('#dateOfBirth').value = date; //Datepicker shows 01/13/17
}

For reference it seems like there may still be a bug in the platform.
https://www.wix.com/velo/forum/coding-with-velo/datepicker-value-disappears-in-custom-form