From 3731c62e1702d202b5f52476772980c5d4b82a5a Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 29 Jan 2015 14:22:45 +0000 Subject: [PATCH] Get validation working with address fields and Angular digest loop --- services/web/app/views/subscriptions/new.jade | 12 ++++++------ .../public/coffee/main/new-subscription.coffee | 15 ++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/services/web/app/views/subscriptions/new.jade b/services/web/app/views/subscriptions/new.jade index fde06d571c..7c2c65cc25 100644 --- a/services/web/app/views/subscriptions/new.jade +++ b/services/web/app/views/subscriptions/new.jade @@ -128,22 +128,22 @@ block content hr .row .col-md-12 - .form-group + .form-group(ng-class="validation.errorFields.address1 ? 'has-error' : ''") label #{translate("billing_address")} input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', ng-model="data.address1", placeholder="#{translate('address')}") - .form-group + .form-group(ng-class="validation.errorFields.address2 ? 'has-error' : ''") input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', ng-model="data.address2", placeholder="#{translate('address')}") - .form-group + .form-group(ng-class="validation.errorFields.state ? 'has-error' : ''") input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', ng-model="data.state", placeholder="#{translate('state')}") .row .col-md-7 - .form-group + .form-group(ng-class="validation.errorFields.city ? 'has-error' : ''") input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="city", ng-model="data.city", placeholder="#{translate('city')}") - .col-md-5 + .col-md-5(ng-class="validation.errorFields.postal_code ? 'has-error' : ''") input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="postal_code", ng-model="data.postal_code", placeholder="#{translate('zip_post_code')}") .row .col-md-7 - .form-group + .form-group(ng-class="validation.errorFields.country ? 'has-error' : ''") select.form-control(data-recurly="country", ng-model="data.country", ng-change="updateCountry()", required) mixin countries_options() .row diff --git a/services/web/public/coffee/main/new-subscription.coffee b/services/web/public/coffee/main/new-subscription.coffee index 60d032fbe4..a67e5fc034 100644 --- a/services/web/public/coffee/main/new-subscription.coffee +++ b/services/web/public/coffee/main/new-subscription.coffee @@ -81,9 +81,10 @@ define [ completeSubscription = (err, recurly_token_id) -> $scope.validation.errorFields = {} if err? - $scope.processing = false - $scope.genericError = err.message - _.each err.fields, (field)-> $scope.validation.errorFields[field] = true + $scope.$apply () -> + $scope.processing = false + $scope.genericError = err.message + _.each err.fields, (field)-> $scope.validation.errorFields[field] = true else postData = _csrf: window.csrfToken @@ -92,10 +93,10 @@ define [ currencyCode:pricing.items.currency plan_code:pricing.items.plan.code $http.post("/user/subscription/create", postData) - .success (data, status, headers)-> - window.location.href = "/user/subscription/thank-you" - .error (data, status, headers)-> - $scope.processing = false + .success (data, status, headers)-> + window.location.href = "/user/subscription/thank-you" + .error (data, status, headers)-> + $scope.processing = false $scope.genericError = "Something went wrong processing the request" $scope.submit = ->