diff --git a/app/assets/javascripts/darkswarm/directives/disable_dynamically.js.coffee b/app/assets/javascripts/darkswarm/directives/disable_dynamically.js.coffee new file mode 100644 index 0000000000..7cff41f3f4 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/disable_dynamically.js.coffee @@ -0,0 +1,12 @@ +# Allows disabling of link buttons via disabled attribute. +# This is normally ignored, ie the link appears disabled but is still clickable. + +Darkswarm.directive "disableDynamically", -> + restrict: 'A' + + link: (scope, element, attrs) -> + element.on 'click', (e) -> + if attrs.disabled + e.preventDefault() + return + diff --git a/app/views/spree/orders/form/_cart_links.html.haml b/app/views/spree/orders/form/_cart_links.html.haml index 8da012cd78..d63d9395ac 100644 --- a/app/views/spree/orders/form/_cart_links.html.haml +++ b/app/views/spree/orders/form/_cart_links.html.haml @@ -1,5 +1,5 @@ .row.links{'data-hook' => "cart_buttons"} - %a.button.large.secondary{href: current_shop_products_path} + %a.button.large.secondary{href: current_shop_products_path, "ng-disabled" => "#{@insufficient_stock_lines.any?}", "disable-dynamically" => true} = t :orders_edit_continue - %a#checkout-link.button.large.primary.right{href: main_app.checkout_path} + %a#checkout-link.button.large.primary.right{href: main_app.checkout_path, "ng-disabled" => "#{@insufficient_stock_lines.any?}", "disable-dynamically" => true} = t :orders_edit_checkout