N
N
Neznayko2017-02-27 07:53:57
Angular
Neznayko, 2017-02-27 07:53:57

How to call validation?

How to trigger validation when another value changes?
For example, there is input-a
field_1
and
field_2.
When field_2 changes, validation and field_1 should be launched (because the field_1 correctness algorithm depends on the value of field_2)
Ps I googled, even found answers, but did not understand anything :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ozknemoy, 2017-02-27
@Neznayko

It's hard to tell without code. it is not clear why the validation of one field should trigger another. validation with angular built-in methods?
here is some code to think about. here 2 soaps must match

<form name="rl.form">
        <div class="form-group">
            <label for="">Введите email :</label>
            <input type="email" class="form-control" required name="email"
                   ng-change="rl.check()"
                   ng-cut="$event.preventDefault()"
                   ng-copy="$event.preventDefault()"
                   ng-paste="$event.preventDefault()"
                   ng-model="rl.email">
        </div>
        <div class="alert alert-danger"
             ng-if="rl.form.email.$touched && (rl.form.email.$error.required ||
                 rl.form.email.$error.email)">Введите правильный E-Mail
        </div>
        <div class="form-group">
            <label for="">Введите повторно e-mail (во избежание ошибки или опечатки):</label>
            <input type="email" class="form-control" required name="emailTwo"
                   ng-change="rl.check()"
                   ng-cut="$event.preventDefault()"
                   ng-copy="$event.preventDefault()"
                   ng-paste="$event.preventDefault()"
                   ng-model="rl.emailTwo">
        </div>
        <div class="alert alert-danger"
             ng-if="rl.form.emailTwo.$touched && (rl.form.emailTwo.$error.required ||
                 rl.form.emailTwo.$error.email)">Введите правильный E-Mail
        </div>
        <div class="alert alert-danger" ng-if="rl.emailNotEqual">
            Почтовые ящики не идентичны
        </div>
        <div class="alert alert-danger" ng-if="rl.emailOccupied">
            Такой пользователь уже зарегистрирован
        </div>

        <div class="alert alert-success" ng-show="rl.allOk">
            Почтовые ящики идентичны
        </div>
    </form>

here, with each change of soaps, I knock on the controller and check if they match

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question