From 0895bd8647bbb72d95fb1fd06b5027685a072fbf Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 3 Sep 2015 17:42:26 +1000 Subject: [PATCH 1/3] Non-integer values cannot be entered into shop front quantities --- .../javascripts/darkswarm/directives/integer.js.coffee | 6 ++++++ app/assets/javascripts/templates/shop_variant.html.haml | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 app/assets/javascripts/darkswarm/directives/integer.js.coffee diff --git a/app/assets/javascripts/darkswarm/directives/integer.js.coffee b/app/assets/javascripts/darkswarm/directives/integer.js.coffee new file mode 100644 index 0000000000..cc70e9bca2 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/integer.js.coffee @@ -0,0 +1,6 @@ +Darkswarm.directive "integer", -> + restrict: 'A' + link: (scope, elem, attr) -> + elem.bind 'input', -> + digits = elem.val().replace(/\D/g, "") + elem.val digits diff --git a/app/assets/javascripts/templates/shop_variant.html.haml b/app/assets/javascripts/templates/shop_variant.html.haml index 6d050d0bde..da5b3609fa 100644 --- a/app/assets/javascripts/templates/shop_variant.html.haml +++ b/app/assets/javascripts/templates/shop_variant.html.haml @@ -11,6 +11,7 @@ .small-5.medium-3.large-3.columns.text-right{"bo-if" => "!variant.product.group_buy"} %input{type: :number, + integer: true, value: nil, min: 0, placeholder: "0", @@ -26,6 +27,7 @@ %span.bulk-input %input.bulk.first{type: :number, value: nil, + integer: true, min: 0, "ng-model" => "variant.line_item.quantity", placeholder: "min", @@ -34,6 +36,7 @@ name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}"} %span.bulk-input{"bo-if" => "variant.product.group_buy"} %input.bulk.second{type: :number, + integer: true, min: 0, "ng-model" => "variant.line_item.max_quantity", placeholder: "max", From 6a2af09006b0f881a012d372a6a830d5ca1ffd4a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 4 Sep 2015 16:15:02 +1000 Subject: [PATCH 2/3] rounding decimal quantities in shopfront --- app/assets/javascripts/darkswarm/directives/integer.js.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/integer.js.coffee b/app/assets/javascripts/darkswarm/directives/integer.js.coffee index cc70e9bca2..e162246122 100644 --- a/app/assets/javascripts/darkswarm/directives/integer.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/integer.js.coffee @@ -2,5 +2,4 @@ Darkswarm.directive "integer", -> restrict: 'A' link: (scope, elem, attr) -> elem.bind 'input', -> - digits = elem.val().replace(/\D/g, "") - elem.val digits + elem.val Math.round(elem.val()) From 60b2596774e9fb9c66225b3b1efc9a23a4941f4f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 4 Sep 2015 16:56:51 +1000 Subject: [PATCH 3/3] disable max quantity unless min quantity is set --- app/assets/javascripts/templates/shop_variant.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/templates/shop_variant.html.haml b/app/assets/javascripts/templates/shop_variant.html.haml index da5b3609fa..04048f3cd0 100644 --- a/app/assets/javascripts/templates/shop_variant.html.haml +++ b/app/assets/javascripts/templates/shop_variant.html.haml @@ -34,8 +34,9 @@ "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}"} - %span.bulk-input{"bo-if" => "variant.product.group_buy"} + %span.bulk-input %input.bulk.second{type: :number, + "ng-disabled" => "!variant.line_item.quantity", integer: true, min: 0, "ng-model" => "variant.line_item.max_quantity",