We help IT Professionals succeed at work.

Server side validation using AngularJS button click

Sandy V
Sandy V asked
on
High Priority
105 Views
Last Modified: 2019-10-09
Using AngularJS i need to do a server side validation for a button click event & based upon the result from server call i need to display a particular section of html page using
data-ng-show="resultdataset.length". If resultdataset has records user need to correct the errors & then click submit button. what attribute should i use to make the server call.

 <button type="submit" id="btnSubmitForm"  ng-click='Validate()' ng-disabled="Config.$invalid || !Config.$dirty"> Save </button>

does ng-click work??

I am submitting form using ng-submit & submitForm() should only be called if there are no records from resultdataset

 <form class="form" name="Config" role="form" ng-submit="submitForm()">

Sorry i am new to AngularJS & trying to figure out stuff.
Comment
Watch Question

Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
remove the ng-submit :
<form class="form" name="Config" role="form">

Open in new window


use ng-click :
<button type="submit" id="btnSubmitForm"  ng-click='Validate()' ng-disabled="Config.$invalid || !Config.$dirty"> Save </button>

Open in new window



$scope.resultdataset = [];
$scope.Validate = function() {
         yourAPI.getDataSet().then(function(data) {
                $scope.resultdataset = data;
                if( $scope.resultdataset > 0 ) {
                     submitForm();
                }
                // else do nothing
         });
}

Open in new window