From c281927372f96ac208c8497ecb0a5daec7cccd6b Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 16 Oct 2018 23:02:26 +0100 Subject: [PATCH] Fix subscription address form. It now clears the state selection when a different country is selected --- .../directives/edit_address_dialog.js.coffee | 6 ++---- .../controllers/address_controller.js.coffee | 14 ++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee b/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee index ca2d2ca817..f52f4379da 100644 --- a/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee +++ b/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee @@ -8,7 +8,8 @@ angular.module("admin.customers").directive 'editAddressDialog', ($compile, $tem scope.$watch 'address.country_id', (newCountryID) -> return unless newCountryID scope.states = CountryStates.statesFor(scope.availableCountries, newCountryID) - scope.clearState() unless CountryStates.addressStateMatchesCountryStates(scope.states, scope.address.state_id) + unless CountryStates.addressStateMatchesCountryStates(scope.states, scope.address.state_id) + scope.address.state_id = "" scope.updateAddress = -> scope.edit_address_form.$setPristine() @@ -33,6 +34,3 @@ angular.module("admin.customers").directive 'editAddressDialog', ($compile, $tem template.dialog(DialogDefaults) template.dialog('open') scope.$apply() - - scope.clearState = -> - scope.address.state_id = "" diff --git a/app/assets/javascripts/admin/subscriptions/controllers/address_controller.js.coffee b/app/assets/javascripts/admin/subscriptions/controllers/address_controller.js.coffee index 30dff9975a..a9ba992b5c 100644 --- a/app/assets/javascripts/admin/subscriptions/controllers/address_controller.js.coffee +++ b/app/assets/javascripts/admin/subscriptions/controllers/address_controller.js.coffee @@ -4,11 +4,17 @@ angular.module("admin.subscriptions").controller "AddressController", ($scope, S $scope.billStates = CountryStates.statesFor(availableCountries, $scope.subscription.bill_address.country_id) $scope.shipStates = CountryStates.statesFor(availableCountries, $scope.subscription.ship_address.country_id) - $scope.$watch 'subscription.bill_address.country_id', (newValue, oldValue) -> - $scope.billStates = CountryStates.statesFor(availableCountries, newValue) if newValue? + $scope.$watch 'subscription.bill_address.country_id', (newCountryID) -> + return unless newCountryID + $scope.billStates = CountryStates.statesFor(availableCountries, newCountryID) + unless CountryStates.addressStateMatchesCountryStates($scope.billStates, $scope.subscription.bill_address.state_id) + $scope.subscription.bill_address.state_id = "" - $scope.$watch 'subscription.ship_address.country_id', (newValue, oldValue) -> - $scope.shipStates = CountryStates.statesFor(availableCountries, newValue) if newValue? + $scope.$watch 'subscription.ship_address.country_id', (newCountryID) -> + return unless newCountryID + $scope.shipStates = CountryStates.statesFor(availableCountries, newCountryID) + unless CountryStates.addressStateMatchesCountryStates($scope.shipStates, $scope.subscription.ship_address.state_id) + $scope.subscription.ship_address.state_id = "" $scope.registerNextCallback 'address', -> $scope.subscription_form.$submitted = true