Pass checkout form to controller method

This commit is contained in:
Rohan Mitchell
2014-11-06 14:11:31 +11:00
parent 75b250d3fe
commit cbb968d87f
4 changed files with 7 additions and 11 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)