mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Dynamically mark quantity field as invalid when stock is incorrect
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
Darkswarm.directive "validateStockQuantity", ->
|
||||
restrict: 'A'
|
||||
require: "ngModel"
|
||||
|
||||
link: (scope, element, attr, ngModel) ->
|
||||
ngModel.$parsers.push (selectedQuantity) ->
|
||||
if parseInt(selectedQuantity) > scope.available_quantity()
|
||||
ngModel.$setValidity('stock', false);
|
||||
else
|
||||
ngModel.$setValidity('stock', true);
|
||||
|
||||
selectedQuantity
|
||||
|
||||
scope.available_quantity = ->
|
||||
on_hand = parseInt(attr.ofnOnHand)
|
||||
finalized_quantity = parseInt(attr.finalizedquantity) || 0 # finalizedquantity is optional
|
||||
on_hand + finalized_quantity
|
||||
Reference in New Issue
Block a user