Promise problems and Datepicker

Hi there.
I read a lot of the threads here but could not wrap my head around this … maybe i am thinking the wrong way. Would be nice if you could help me out and put me in the right direction. Please :slight_smile:

I have this code:

if(file.length != 0){
 // ...some code
}else{
  let theDate = showDatePicker()
  await theDate.then(function(dateValue){
    cLog("foobar: " + dateValue)
  }) 
  cLog("Hossa") 
}

async function showDatePicker() {
  let pickD = new DatePicker()
  pickD.pickDate().then(function(pickValue){
    return pickValue()
  }, function(){
    return false
  })
}

In the „else“ area i want to present the DatePicker and wait until a date is selected - or the picker gets canceled.

But as soon as the picker is presented the two cLog (console.log) values are printed to the console, so the await and .then seems not to work.

What am i doing wrong? Where is my thinking off?
Thanks in advance!

Does this help?

let date = await showDatePicker()
console.log(date)

async function showDatePicker() {
  let picker = new DatePicker()
  let date = await picker.pickDate()
  return date
}
1 Like

Indeed it does @rob .
Thank you! I will dig into it.