2017-04-25 15 views
0

私は自分のフォームで電子メールの検証を行っています。ユーザーがすでに登録されている場合は、アラートが表示され、null値のフォームがリセットされます。私はアラートメッセージとデータをフォームに保持する必要があります。 ありがとうございます。 https://plnkr.co/edit/WhdRmJmLs69yaf6Q2uYI?p=previewanglejsで検証エラーの後にフォームに値を保持する方法

<div class="form-group"> 
 
       <label class="control-label col-sm-2" for="firstName">First Name:</label> 
 
       <div class="col-xs-4"> 
 
        <input type="text" class="form-control" id="firstName" ng-disabled="!edit" name="firstName" ng-model="user.firstName" ng-required="true"> 
 
        <span style="color:red" ng-show="userForm.myName.$touched && userForm.myName.$invalid">Please enter a First Name</span> 
 
       </div> 
 

 
       <label class="control-label col-sm-2">Email:</label> 
 
       <div class="col-xs-4"><input type="email" id="email" class="form-control" ng-disabled="!edit" name="email" ng-model="user.email" ng-required="true"> 
 
        <span style="color:red" ng-show="userForm.email.$touched && userForm.email.$invalid">Please enter valid email ID</span> 
 
       </div> 
 
      </div> 
 
<div class="panel-footer"> 
 
      <button type="button" ng-click='edit=!edit'id="Edit" ng-show="!edit" class="btn btn-default" >Edit</button> 
 
      <button ng-show="edit" id="save" type="submit" ng-click='addOrModifyUser(user)' class="btn btn-default" 
 
        ng-disabled="userForm.$invalid">Save 
 
      </button> 
 
      <a ng-if="user.accountId" ui-sref="account.locations.contacts({accountId: user.accountId})"> 
 
       <button type="type" class="btn btn-default">Cancel</button> 
 
      </a> 
 
      </div>

I?p =プレビュー

+0

$ http呼び出しの前に別​​の変数に保存して、一意性を検証します。 –

+0

あなたのプラークは、あなたが持っている問題を示すデモではありません。 HTMLページにはAngular JSファイルは含まれていません。 – Hoa

+0

Emailの一意性をチェックしていますか?指示の方法で行ってください。今は '$ state.reload()'と '$ location.path()'を使って完全なページをリロードしますので、明らかにすべてのデータを失います。 –

答えて

0

あなたの問題はここにあるが、これは私が角度1でカスタム電子メールの検証チェックを解決しただろうかです正確に何を知ってはいけません。バツ。

HTML:

<form ng-submit="submit()"> 
    <input type="email" class="form-control" id="email" name="email" placeholder="email" ng-model="formModel.email" /> 
    <span ng-show="formModel.$submitted && formModel.teamName.$error.exists">Email already exists</span> 
</form> 

のJs:(あなたの角度のコントローラで) "EmailService" は、電子メールがあなたのバックエンドに対して存在するかどうかをチェックする選択のあなたのHTTPサービスのようになります。

myApp.controller('mainController', function($scope, EmailService) { 


    $scope.submit = function() { 

     $scope.formModel.email.$setValidity("exists", true); 
     EmailService.emailExist($scope.formModel.email, { // check if email exists 
      success: function(exists) { 

       $scope.$apply(function(){ 
        $scope.formModel.email.$setValidity("exists", !exists); // set validation flag 
       }); 

       if($scope.formModel.$valid) { 
        // submit if valid 
       } 
      } 
     } 
    } 
} 

幸運を祈る!

関連する問題