Fix subscription address form. It now clears the state selection when a different country is selected

This commit is contained in:
luisramos0
2018-10-16 23:02:26 +01:00
parent 1804bf5a2b
commit c281927372
2 changed files with 12 additions and 8 deletions

View File

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

View File

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