Answer the question
In order to leave comments, you need to log in
How to update validation in step by step registration form in angular?
I am developing a step-by-step registration form in angular, I ran into a problem: the fields filled in the first step (with validation) are restored from localstorage when stepping back (for example, I returned from the 2nd step to correct the data in the first), while the validation does not occur again, the fields have the status ng-pristine .
How to update validation?
Answer the question
In order to leave comments, you need to log in
Try playing with the form, for example by calling form.$setDirty()
$setDirty()
in the controller
And experiment with the form controller
All right, actually.
ng-dirty appears when the user has worked with the form.
Before that, there will be ng-pristine.
But the validation itself (ng-invalid-required, for example) is also updated after the model is changed programmatically.
So you most likely need to slightly change the logic in your controller. I made it so that I have a variable that is responsible for showing errors or not.
The logic is as follows:
- the user edits a new form, we do not show him anything (why distract him?)
- by clicking on "Save", "Forward", etc., we check if the form is not valid, we turn on the display of errors, and wait until it fixes all the errors, and the availability of the button is determined by form.$dirty
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question