Prevent close panel without saving

Hi, I’m trying to implement a routine to Prevent close panel without saving
I have tried a lot of things with onClose and beforeClose but the panel get closed as soon as the confirm dialog appears, without wait the user response

what is wrong ?

rpanel.on(‘beforeClose’, function (e) {
//e.preventDefault(); cause error

myApp.dialog.confirm('¿Exit without saving?', function () {        
    
  rpanel.close();            
  //return true;  
}, function () {  // cancel      
    return false;    //not working
});

});