Submit data when All TextBox in Table Row has value in AngularJS

Last Reply one month ago By skp

Posted one month ago

How to submit data into database only when the textbox has some value in angularjs.

Here, only the first row data is taken into the database and when the first row textbox data is empty, the remaining textbox data is not getting inserted.

For Eg : 

If the textbox value is 0, the data should not get into the database and if the textbox value is 1, 100, etc, the data should get into the database 

        <div class="bg-white mb-1">
            <div class="row m-1 p-1" ng-repeat="item in mydata">
                <div class="col-md-1 pull-left airways-info-sect">
                    <span class="fli-code">Serial No</span>
                    <span class="airways-name" style="text-align:center;">{{$index + 1}}</span>
                </div>
                <div class="col-md-4 pull-left airways-info-sect">
                    <span class="fli-code">Part Name</span>
                    <span class="airways-name" style="text-align: left;">{{item.PartName}}</span>
                </div>
                <div class="col-md-2 pull-left airways-info-sect">
                    <span class="fli-code">No Of Pallets</span>
                    <span class="airways-name ">
                        <input type="number" min="0" class="" placeholder="" ng-model="item.num" ng-init="item.num=0" ng-change="calc($index)" required="" style="border:1px solid #333; width:20%; text-align:right" /><i class="mr-3 fa fa-plus-square-o" style="font-size:22px; padding-left:5px; position:absolute;"></i>
                    </span>
                </div>
                <div class="col-md-1 pull-left airways-info-sect"> 
                <span class="fli-code">Pallet Qty</span> 
                    <span class="airways-name" style="text-align:right;">{{item.PalletCapacity}}</span>  
                </div>
                <div class="col-md-1 pull-left airways-info-sect"> 
                    <span class="fli-code">Accept Qty</span> 
                    <span class="airways-name">{{item.Numbers}}</span>  
                </div>
                <div class="col-md-1 pull-left airways-info-sect"> 
                    <span class="fli-code">Issued Qty</span> 
                    <span class="airways-name" style="text-align:right;">{{item.IssuedQty}}</span>  
                </div>
                <div class="col-md-1 pull-left airways-info-sect">
                    <span class="fli-code">Issue Qty</span>
                    <input type="number" class="" placeholder="" ng-model="item.mul" ng-init="item.mul=0" required="" style="border: 1px solid #333; width: 90%; text-align: right" />
                </div>
                <div class="col-md-1 pull-left airways-info-sect">
                <span class="fli-code">Stock</span> 
                    <span class="airways-name" style="text-align:right;">{{item.Stock}}</span>  
                </div>
            </div>
        </div>
        <input type="button" class="btn btn-primary bg-purple my-2 float-right mt-2 border-0" value="{{btntext}}" ng-click="submit()" ng-disabled="isDisabled" data-toggle="modal" data-target="#myModal2">   

 

            if ($scope.mydata[0].mul > 0 && typeof ($scope.plNo) != "undefined") {           
                $http({
                    method: "POST",
                    url: apiUrl + "/api/Warehouse/AddIssueDetails",
                    data: JSON.stringify(issueDetails),
                    dataType: 'json',
                    contentType: 'application/json'
                }).then(function (data, status) {
                });
            } else {
                $window.alert("Please enter some details");
            }

 

You are viewing reply posted by: skp one month ago.
Posted one month ago

I have modified the answer according to my requirement, this is the answe for my question

$scope.submit = function () {       
        debugger;
        var a = $scope.mydata.length;       
        for (var i = 0; i < a; i++) {
            var issueDetails = {
                "InvoiceId": $scope.selectedInvoice[0].InvoiceId,
                "IssueDate": $scope.currentdate,
                "PackingListNo": $scope.plNo,
                "DispatchId": $scope.mydata[i].DispatchId,
                "IssueQty": $scope.mydata[i].mul,
                "CreatedBy": $scope.username
            };            
            if ($scope.mydata[i].mul > 0 && typeof ($scope.plNo) != "undefined") {
                $http({
                    method: "POST",
                    url: apiUrl + "/api/Warehouse/AddIssueDetails",
                    data: JSON.stringify(issueDetails),
                    dataType: 'json',
                    contentType: 'application/json'
                }).then(function (data, status) {
                    $scope.issueDetails = "";
                });
            }
            else {
                $window.alert("Please ensure that required fields are entered");
            }
        }
}