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.