I have slightly modified the solution. On top of the page (outside the modal panel) I added a hidden form field that just indicates if validation messages exist.
1 2 3 4 5
The method property hasMessages is implemented as follows:
1 2 3