Dispatching custom event to close a form