Checkout: When error, open offending accordion section

This commit is contained in:
Rohan Mitchell
2014-11-06 16:45:21 +11:00
parent 4389389d44
commit 57e7bc9504
2 changed files with 15 additions and 3 deletions

View File

@@ -6,6 +6,15 @@ Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout, CurrentHub) ->
billing: false
storage.bind $scope, "accordion", {storeName: "accordion_#{$scope.order.id}#{CurrentHub.hub.id}#{$scope.order.user_id}"}
$scope.show = (name)->
$scope.accordion[name] = true
$scope.show = (section)->
$scope.accordion[section] = true
$scope.$on 'purchaseFormInvalid', (event, form) ->
# Scroll to first invalid section
# TODO: hide all first
# TODO: Use Object.keys($scope.accordion)
sections = ["details", "billing", "shipping", "payment"]
for section in sections
if not form[section].$valid
$scope.show section
break

View File

@@ -21,4 +21,7 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu
$scope.purchase = (event, form) ->
event.preventDefault()
$scope.submitted = true
$scope.Checkout.submit() if form.$valid
if form.$valid
$scope.Checkout.submit()
else
$scope.$broadcast 'purchaseFormInvalid', form