Only close a submitted dialog if the form validates

This commit makes sure that the form is considered valid by the browser (checks for input[required] and input[pattern] and the like) before actually preventing the form submission and closing the dialog.

(Seems like GitHub's online editor decided to add a newline at the end. Sorry about that.)