I am trying to create a little form with validation inside a modal dialog. The dialog has a cancel button which should hide the dialog:
I've created a small project to verify it:
https://embed.plnkr.co/jF202JGxI0f7BjeKhL7A/
The name field has a validation which is triggered if the name is left empty. The input field gets focus when the dialog is shown.
The problem is now pressing cancel without entering any text.
The validation kicks in before the button's click handler is triggered. The result is that the error message is displayed. This moves the cancel button down and the click goes to nirvana.
You can verify this behavior by clicking the top part of the cancel button. If you click the bottom part everything works as expected (except that I would prefer not to show the validation message at all).
So... what I'd like to have:
Trigger validation if user
- leaves the field by pressing tab
- clicks on next field (in some other dialog with more fields)
- clicks on ok / create metric
- changes the field content
Trigger no validation if user
- clicks on cancel
- clicks outside of the dialog
