To validate fields and show error messages I am using this way:
Let’s explain. When you loading the page, input will mark as invalid (first of all because it empty) and get the red shadow. See such a error quite odd, bacause you even didn’t write anything. So to set invalid in proper time, use
$dirty flag. If it’s true that means the field was changed. And when
$dirty is false and
$valid is true, you are really write something wrong.
Now let’s suppouse we wrote proper value in input and click button which should save the value somewhere and reset the form.
Will work, but your
$dirty flag still is true. And just add this line after reseting the form:
Ok, now it’s working.