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.
Merge pull request #4682 from jaswilli/modal-error

Prevent error when closing modal dialog