Angularjs has great infrastructure for form validation and showing error messages. But, I am in a situation that I have to show a warning message to a user in a specific scenario. Here is the diagram of my simple form
The form has required and pattern validation applied on both fields. In addition to this validation I want a warning message to be displayed to the user if VatAmount
is not 20 percent of the InvoiceAmount
. The warning will differ from validation in following aspects
- It will not prevent the form submission
- It will only appear if both fields (InvoiceAmount and VATAmount) are valid
- The warning should have a button or link that would read "Change and proceed". When user presses that button the warning message will hide and focus will be set to VATAmount field.
I believe this is a prefect use case for creating a directive. Actually, I have given it a try and put my effort in the form of a plunker. But my directive does not handle following cases
- It appears even if the fields involved in warning are invalid
- The show and hide functionality is not implemented (have no idea how to target it)
Here is the link to the plunker