0

I am using the presending event of InboxSDK to check for a condition before sending the email. For the case selectedProject!==0, email is not getting sent. Does anyone have any comments.

composeView.on('presending', (event) => {
  if(selectedProject!==0){
    //console.log(selectedProject);
    composeView.send();

  }else{
    console.log(selectedProject);
    event.cancel();
    console.log('please select a project for the email');
    alert('please select a project for the email');
    initDropdown();//show the dropdown to select projects
  }
egala
  • 1
  • Did you try cancel first and only use composeView.send() if condition is true or just don't do anything id condition is met (invert condition). I would assume if you don't cancel the send will happen after passing through your if-else anyways and maybe triggering send will just create a loop? – Honkalonkalooooohhh Jun 22 '20 at 10:14

1 Answers1

0

From the presending handler if you want to send, you need to end the function by returning, if you call composeView.send(); it gets on a cycle calling the presending handler again.

composeView.on('presending', (event) => {
  if(selectedProject !== 0){
    return;
  } else {
    ...
    event.cancel();
    ...
  }

If you want to send later, you need to set a flag that is checked on the presending event to avoid running it again.

composeView.on('presending', (event) => {
  if(myForceSendFlag || selectedProject !== 0){
    return;
  } else {
    ...
    event.cancel();
    ...
  }

I know it's a bit late, but I hope this helps.

piedra
  • 1,343
  • 14
  • 13