diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee index 2ab0da6ff6..ed99c6bd41 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee @@ -18,7 +18,7 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu $scope.enabled = !!CurrentUser - $scope.purchase = (event)-> + $scope.purchase = (event, form) -> event.preventDefault() $scope.submitted = true - $scope.Checkout.submit() if $scope.checkout.$valid + $scope.Checkout.submit() if form.$valid diff --git a/app/views/checkout/_form.html.haml b/app/views/checkout/_form.html.haml index 4d7749760c..1944dfffe1 100644 --- a/app/views/checkout/_form.html.haml +++ b/app/views/checkout/_form.html.haml @@ -2,7 +2,7 @@ html: {name: "checkout", id: "checkout_form", novalidate: true, - "ng-submit" => "purchase($event)"} do |f| + "ng-submit" => "purchase($event, checkout)"} do |f| = inject_available_shipping_methods = inject_available_payment_methods diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index 8609fd7a16..df454e1701 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -1,5 +1,5 @@ %orderdetails - = form_for current_order, url: "#", html: {"ng-submit" => "purchase($event)"} do |f| + = form_for current_order, url: "#", html: {"ng-submit" => "purchase($event, checkout)"} do |f| %fieldset %legend Your order %table @@ -25,7 +25,7 @@ %th= label %td= total - //= f.submit "Purchase", class: "button", "ng-disabled" => "checkout.$invalid", "ofn-focus" => "accordion['payment']" + //= f.submit "Purchase", class: "button", "ofn-focus" => "accordion['payment']" %a.button.secondary{href: cart_url} %i.ofn-i_008-caret-left Back to Cart diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee index 9cd2c5a06c..82b402d50b 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee @@ -43,16 +43,12 @@ describe "CheckoutCtrl", -> scope.submitted = false it "delegates to the service when valid", -> - scope.checkout = - $valid: true - scope.purchase(event) + scope.purchase(event, {$valid: true}) expect(Checkout.submit).toHaveBeenCalled() expect(scope.submitted).toBe(true) it "does nothing when invalid", -> - scope.checkout = - $valid: false - scope.purchase(event) + scope.purchase(event, {$valid: false}) expect(Checkout.submit).not.toHaveBeenCalled() expect(scope.submitted).toBe(true)