闪电战:
https://stackblitz.com/edit/angularjs-vc9lg5
我有一个号码
Total expense
和一个数据表。
有一个专栏
Amt
金额
在
ng-change
deductedTillNow
和
balanceLeftInExpense
.
您可以在chrome扩展中看到
$scope
变量
现在扣除
平衡
在右边。当我试图通过输入从第一行扣除剩余的500时
50
变成450。
,
0
,即
是
450
500大于450。如何允许输入500?
//calculate amount till now
$scope.deductedTillNow = 0;
for (let j = 0; j < $scope.amountLedgerListArray.length; j++) {
if($scope.amountLedgerListArray[j].adjustAmount){
$scope.deductedTillNow = $scope.amountLedgerListArray[j].adjustAmount + $scope.deductedTillNow;
}
}
//calculate balance left in expense
$scope.balanceLeftInExpense = $scope.totalExpenseAmount - $scope.deductedTillNow;
平衡
-验证:
if(item.adjustAmount > $scope.balanceLeftInExpense){
item.adjustAmount = item.adjustAmount.toString();
item.adjustAmount = item.adjustAmount.substring(0, item.adjustAmount.length - 1);
item.adjustAmount = parseInt(item.adjustAmount);
}
html:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Payment Ref no</th>
<th>Date</th>
<th>Amt</th>
<th >Adjust amount</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in amountLedgerListArray">
<td>
{{item.payment_ref_no}}
</td>
<td>
{{item.payment_date}}
</td>
<td>
{{item.amount}}
</td>
<td>
<input type="number" name="sgst" class="form-control"
ng-disabled="item.isDisabled" autocomplete="off"
ng-change="calculateBalanceAndRestrict(item)"
ng-class="{'borderRedError' : expense.$invalid}"
ng-model="item.adjustAmount" onkeypress="limitKeyPress(this, 10, event)" />
</td>
</tr>
</tbody>
</table>
编辑
“金额”列中的数据是已支付的预付款。现在有一个费用(本例中为1000。请参见屏幕截图)
Total expense:1000
).我可以从表中的任何一行中扣除
金额
这里我从第三行扣除了500英镑(现在的余额是500英镑)。我可以从最上面的两行中扣除剩下的500。第二行的100(因为它只有100)和第一行的剩余500,或者第一行的剩余500。
我这样验证:在更改输入框时,我检查输入的金额是否大于输入的所有金额之和(
现在扣除
).当我现在开始在第一行输入时,费用中的余额会被计算出来。当我输入50时,左边的余额是450(1000-500(第三行)+50(第一行))。
当我在50之后为第一行剩余的500键入0时,左边的余额是450。因此,我的验证不允许这样做(输入的500大于450)。我需要允许输入500。