0

送信時に、クライアントと API の両方でフォームを検証しています。バックエンドで検証が失敗した場合、クライアントの検証が失敗した場合と同じメッセージを表示したいと考えています。これを行うには、フィールドがバックエンドで失敗したときに次のコードを使用します。

#Template
<span class="registration-error" ng-show="accPasswordForm.password.$error.required">*</span>
<span class="registration-error" ng-show="accPasswordForm.password.$error.authfail">Authentication failed</span>
<input ng-model="changePasswordForm.password" name="password" type="password" authfail required/>

#Controller ( I set this if the password field throws a validation error in my API )
scope.myForm.password.$setValidity('authfail', false);

これは問題なく動作しますが、問題は、パスワード フィールドに再度入力を開始するときに、この $setValidity を true に設定することです。必要なエラーと同じ動作。フィールド入力を監視するためにさまざまな方法を試しましたが、常に機能しないようです。

これを機能させる方法についてヒント/コードスニペットを教えてくれる人はいますか?

4

1 に答える 1

0

または、これを行うことができます:

#Template
<span class="registration-error" ng-show="accPasswordForm.password.$error.required">*</span>
<span class="registration-error" ng-show="server_error_auth || accPasswordForm.password.$error.authfail">Authentication failed</span>
<input ng-model="changePasswordForm.password" ng-change="server_error_auth=false" name="password" type="password" authfail required/>

#Controller ( I set this if the password field throws a validation error in my API )
$scope.server_error_auth = true;
于 2013-08-23T08:27:15.617 に答える