mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +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
|
||||
@@ -103,7 +103,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
input.warning {
|
||||
input.ng-invalid-stock {
|
||||
border: 1px solid $clr-brick;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
:min => 0, "ofn-on-hand" => "#{variant.on_demand && 9999 || variant.on_hand}",
|
||||
"finalizedquantity" => finalized_quantity, :class => "line_item_quantity", :size => 5,
|
||||
"ng-model" => "line_item_#{line_item.id}",
|
||||
"ng-class" => "{ warning: #{@insufficient_stock_lines.andand.include? line_item} }"
|
||||
"validate-stock-quantity" => true
|
||||
%td.cart-item-total.text-right{"data-hook" => "cart_item_total"}
|
||||
= line_item.display_amount_with_adjustments.to_html unless line_item.quantity.nil?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user