2017-11-03 6 views
0

フォームタグ内にいくつかのフィールドがあり、フォームタグの外にボタンがあります。フォーム内のフィールドが空白の場合は、フォームを送信しないでください。このため、私はrequired属性を使用しましたが、サブミットボタンが<form>の外にあり、novalidate属性も使用していたので、機能しませんでした。何も動作していないようです。HTMLと角形の数字

FirstNameMiddleName私のフォームを送信してはならないこれらのフィールドのいずれかを満たすことなく、他の多くの分野があるよう
<section id="profile" class="content-header"> 
    <div class="thumbnail"> 
    <button type="submit" class="btn btn-block btn-success" ng-if="!viewProfile" ng-click="updateProfile();">SUBMIT</button> 
    </div> 
    <div class="row"> 
    <form name="profileForm" role="form"> 
     <div class="form-group col-md-6"> 
     <label for="firstName"> First Name </label> 
     <input type="text" class="form-control" id="firstName" ng- model="profileDetails.firstName" ng-disabled="viewProfile" required/> 
     </div> 
     <div class="form-group col-md-6" ng-if="userDetails.role==0"> 
     <label for="firstName"> Middle Name </label> 
     <input type="text" class="form-control" id="middleName" ng- model="profileDetails.middleName" ng-disabled="viewProfile" /> 
     </div> 
    </form> 
    </div> 
</section> 

は、誰もが私は、このための最善のアプローチを提案することができます:

以下は私のコードです。私angularControllerは次のとおりです。

(function() { 
    function profileController($scope, profileFactory, $loading) { 
    $scope.updateProfile = function() { 
     $loading.start("main"); 
     profileFactory 
     .updateProfile($scope.profileDetails) 
     .then(function(response) { 
      var updatedUserDetails = response.user; 
      if (updatedUserDetails.imagePath !== null) { 
      $scope.profileDetails.imagePath = updatedUserDetails.imagePath; 
      $scope.profileDetails.profieImageBytes = updatedUserDetails.profieImageBytes; 
      } 
      angular.extend($scope.userDetails, $scope.profileDetails); 
      $scope.editProfile(); 
     }) 
     .catch(function() { 
      $loading.finish("main"); 
     }); 
    }; 
    $loading.finish("main"); 
    } 
    profileController.$inject = ["$scope", "profileFactory", "$loading"]; 
    angular 
    .module("vResume.profile") 
    .controller("profileController", profileController); 
})(); 
+1

フォームをJavaScript経由で 'updateProfile()'関数で送信できます。この質問を参照してください:https://stackoverflow.com/questions/9855656/how-to-submit-a-form-using-javascript – mrogers

+0

あなたのjsも投稿してください –

+0

私たちのアプリケーションでは、JavaScriptを使用していませんでした。これは完全にAngular -mrogers – vyas

答えて

1

あなたは一般的にNG-無効このために、フォーム上の.$invalidフィールドを使用します。

<button type="submit" class="btn btn-block btn-success" ng-disabled="profileForm.$invalid" ng-if="!viewProfile" ng-click="updateProfile();">SUBMIT</button> 

angularjs docsを参照してください。

+0

YAAはすでに、私はすべてのフィールドを与えるdoesntの場合、フォームは – vyas

+0

に提出され、それも働いていなかった、という試みたも-mrogersスニペット投稿AngularJSを使用しているプレーンなJavaScriptを使用していないと言うことを意味 –

+0

ボタンからtype = "submit"を取り除いてみてください。 –

関連する問題