Ruslan Khissamov2016-03-16 12:24:56
Ruslan Khissamov, 2016-03-16 12:24:56

Angular2 form validation?

Hello colleagues!
Need your help in setting css validation classes using angular2.
Below is my form and the problems I am getting.

  <form [ngFormModel]="" (ngSubmit)="submit()">
      <fieldset class="form-group" [class.error]="!name.valid && name.derty" [class.success]="name.valid"> // Получаем ошибку форма не работает
        <label class="form-control-label" for="name">Email</label>
          class="form-control" id="name"         
          [class.error]="!name.valid && name.dirty" // Получаем ошибку форма не работает
          [class.success]="name.valid" // Получаем ошибку форма не работает
          [class.error]="!name.valid && name.dirty" // Форма работает класс добавляется
          [class.success]="name.valid" // Форма работает класс добавляется
        <control-messages control="name"></control-messages>

Here such option works from the first angular you work in the second.
Ng-class="email.valid ? 'Has-success': 'has-danger'"
But with the new form it does everything in danger, which is not good, that is, there is no check for dirty or pristine

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Ruslan Khissamov, 2016-03-16

A variant like this
[ngClass]="{'has-error': name.dirty == true && name.valid == false}"
in the first angular worked like this
ng-class="{'has-error': name.dirty && !name.valid}"
maybe there are other solutions I'm waiting for

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question