I have a table with input inside it to allow users edit the quantity of goods, the total values of all goods in the bill is calculated when user input the quantity via ng-change
. In ng-change
, i will check if the quantity is large than current stock, i will reset it to old value and do not update total values (plus show msg err etc.....). Everthing gone fine, but my only problem is I can not make the input update with the model.
<table st-table="goodsOfBillList" st-safe-src="sellDetailList" class="table table-striped">
<tr ng-repeat="row in goodsOfBillList" st-select-row="row" st-select-mode="single" ng-show="!sellBillCtrl.isLoading">
<td>
<input id="quantity" ng-model="row.quantity" ng-model-options="{ updateOn: 'blur' }"
placeholder="current stock : {{row.currentStock}}"
class="form-control input-md" required="" type="number" min="1" max="{{row.currentStock}}"
ng-change="updateTotal(row, '{{row.quantity}}')">
</td>
</tr>
</table>
When i input an invalid value (50) like the picture below, quantity is reset back to previous value (5), but the input in the model doesn't update
$scope.updateTotal = function (row, oldVal)
{
//because I set max value, if I input an invalid value, row.quantity become undefined
//Checked by using alert()
if(typeof row.quantity === "undefined")
{
row.quantity = oldVal;
alert(JSON.stringify(row));
return;
}
//logic if valid value
};
i am using input in smart-table, and the table inside a boostrap modal