A
A
Andrello2013-12-24 21:23:16
JavaScript
Andrello, 2013-12-24 21:23:16

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

2 answer(s)
M
maxaon, 2013-12-24
@maxaon

Try playing with the form, for example by calling form.$setDirty()
$setDirty()
in the controller And experiment with the form controller

_
_ _, 2014-01-12
@AMar4enko

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 question

Ask a Question

731 491 924 answers to any question