Prevent error when closing modal dialog

No Issue
- Moved sendAction outside of the event handler as calling it
  from inside was generating an error in the console.