I have a form and each field has an error span ng-show="submitted && <condition>" (where condition is a typical error check). The var 'submitted' is set to true in the form handler (triggered by submit) and if true I make server side calls. I don't want to show errors until the user clicks submit to take the next action.
My problem is that setting 'submitted' to true and then checking form.$valid in the same method doesn't work. The form is always valid. I see validation errors and the rest of the method process as though there were no errors. Not good. Immediately after the method completes it seems the validation runs its course and form.$valid is now false. I've dumped the 'form' and 'form.$valid' to the console and see two different values - aggravating. I changed the submit call to go to a new method that sets submitted=true, then calls the form handler via a $timeout (I've set it as low as 1ms with success) and now when the form processing method checks form.$valid it's false and everything works as it should. This feels like a hack. Is there a better way to have a control var for form validation messages yet get an accurate response from form.$valid? I've read it's not appropriate to trigger validation manually. My solution feels like a hack for something that should be straight forward. Am I missing something, or is there an issue with AngularJS that could be improved? -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
