How to make ngMessage for required fields only show when dirty or submitting a form?

前端 未结 12 2600
一个人的身影
一个人的身影 2020-12-08 02:31

I\'m using AngularJS 1.3.0 RC0 and angular-messages. ng-messages dutifully shows error messages for those \"required\" fields when a form is initially loaded and pristine. S

12条回答
  •  难免孤独
    2020-12-08 03:02

    Instead of using the ng-if suggested you could do something like...

    Required field

    And on your submit button add:

    ng-click="submitted=true"
    

    You'd probably want to change '$scope.submitted' back to false when you type again, so you could add this to your text/email input:

    ng-keyup="submitted=false"
    

    That way only the submit button will change '$scope.submitted' to true and everything else you do will set it to false, therefore hiding your error message until you click the submit button.

提交回复
热议问题