mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Pass checkout form to controller method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user