O
O
Ostap262015-07-25 14:16:28
Angular
Ostap26, 2015-07-25 14:16:28

How to fix ng-disabled error?

<div ng-app="test-app">
   <div ng-controller="ctrlForm" >
      <form name="form" class="css-form" ng-submit="submit()" novalidate>
         <div class="title">Регистрационная форма</div>
         <div class="forInput">Имя: </div>
         <input type="text" ng-model="user.login" name="uName" ng-pattern="/^([а-яёА-ЯЁ])*$/" required />
         <div ng-show="form.$submitted || form.uName.$touched">
            <div ng-show="form.uName.$error.required">Поле должно быть заполнено!</div>
            <div ng-show="form.uName.$error.pattern">Имя должно содержать только буквы кириллицы</div>
         </div>
         <div class="forInput">E-mail: </div>
         <input type="email" ng-model="user.email" name="uEmail" required />
         <div ng-show="form.$submitted || form.uEmail.$touched">
            <div ng-show="form.uEmail.$error.required">Поле должно быть заполнено!</div>
            <div ng-show="form.uEmail.$error.email">Неправильный email!</div>
         </div>
         <div class="forInput"> Телефон: </div>
         <input type="text" ng-model="user.phone" ng-pattern="/^\+380\d*$/" name="phone" required />
         <div ng-show="form.$submitted || form.phone.$touched">
            <div ng-show="form.phone.$error.required">Поле должно быть заполнено!</div>
            <div ng-show="form.phone.$error.pattern">Номер должен быть вида +380*********</div>
         </div>
         <div class="forInput">Пароль: </div>
         <input type="password" ng-model="user.password" ng-minlength="6" name="password" required />
         <div ng-show="form.$submitted || form.password.$touched">
            <div ng-show="form.password.$error.required">Поле должно быть заполнено!</div>
            <div ng-show="form.password.$error.minlength">Пароль должен состоять более чем из 6 символов</div>
         </div>
         <div class="forInput"> Повторите пароль: </div>
         <input type="password" ng-model="password2" name="password2" required />
         <div ng-show="form.$submitted || form.password2.$touched">
            <div ng-show="form.password2.$error.required">Поле должно быть заполнено!</div>
            <div ng-show="password2!=user.password">Пароли не совпадают</div>
         </div>
         <input type="submit" ng-disabled="!form.$valid" value="Отправить">
      </form>
   </div>
</div>

At the end of the code on the submit button, if I write such a condition ng-disabled="!form.$valid && user.password!=password2" then it stops working

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-07-25
Protko @Fesor

because you have the wrong condition. You have to use OR.
ps and even better - use directives. They are even ready-made:
ngmodules.org/modules/angular-input-match

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question