Test if the form is valid before closing the windows.