effective_addresses 1.3.2 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5688457f9a6889758119802194fa1be36cc5452
4
- data.tar.gz: 85af035d0d760ee4e4e997bc8db4611d500d9464
3
+ metadata.gz: e2a0de702ce06b137ff76dd3369442ddf9ba5f94
4
+ data.tar.gz: 698755ab5f757fcbb8ee8c1d481b8e5df0bf238c
5
5
  SHA512:
6
- metadata.gz: c357eead61b53be0d8a0cb5a40d560a9ba76c707fec9d5ca0bd0d2dc6964b2317d8cb47fe33870617f11e1507ca0a647b81bdbccc7b18a40c1ac6eca8a6feaf4
7
- data.tar.gz: 20bc9eed1de75eb80069270b242810f43c71097388119a8082358ebdab1b926f2fe6dc08feb2324cc72bcf513b5cc630b092165c3ccd255f469805746b914f41
6
+ metadata.gz: 5cb549e5323b92b3b312d9ca9b33e66d7959a4f9b7d7b628f384522bf8a8405c1f8ac3f845fe2f65844e49a94d558d70223beda6e311524d380c6b2bfe08c005
7
+ data.tar.gz: 236e4f110bc5956d46b1ba0c9ad9fd0ed0732ff74995631b630b38ba33ba9c3d0989535f8ea1af280247fa4b0c885b427fee308706f056facdcef94d2d18c71a
@@ -1,20 +1,37 @@
1
- $(document).on 'change', "select[data-effective-address-country]", (event) ->
2
- country_code = $(this).val()
3
- uuid = $(this).data('effective-address-country')
4
- nested_fields = $(this).closest('.nested-fields')
5
- form = $(this).closest('form')
1
+ loadSubregions = ($countrySelect) ->
2
+ $.each $countrySelect, (index, countrySelector) ->
3
+ $particularCountrySelect = $(countrySelector)
4
+ countryCode = $particularCountrySelect.val()
5
+ uuid = $particularCountrySelect.data('effective-address-country')
6
6
 
7
- # clear postal_code values on country change
8
- (nested_fields || form).find("input[data-effective-address-postal-code='#{uuid}']").val('')
7
+ $nestedFields = $particularCountrySelect.closest('.nested-fields')
8
+ $form = $particularCountrySelect.closest('form')
9
9
 
10
- # load state options
11
- url = "/addresses/subregions/#{country_code}"
12
- state_select = (nested_fields || form).find("select[data-effective-address-state='#{uuid}']").first()
10
+ $container = if $nestedFields.length == 0 then $form else $nestedFields
13
11
 
14
- if country_code.length == 0
15
- state_select.prop('disabled', true).addClass('disabled').parent('.form-group').addClass('disabled')
16
- state_select.html('<option value="">Please choose a country first</option>')
17
- else
18
- state_select.prop('disabled', false).removeClass('disabled').parent('.form-group').removeClass('disabled')
19
- state_select.find('option').first().text('loading...')
20
- state_select.load(url)
12
+ # clear postal_code values on country change
13
+ $container.find("input[data-effective-address-postal-code='#{uuid}']").val('')
14
+
15
+ # load state options
16
+ url = "/addresses/subregions/#{countryCode}"
17
+ $stateSelect = $container.find("select[data-effective-address-state='#{uuid}']:first")
18
+
19
+ if countryCode.length == 0
20
+ $stateSelect.prop('disabled', true).addClass('disabled').parent('.form-group').addClass('disabled')
21
+ $stateSelect.html('<option value="">Please choose a country first</option>')
22
+ else
23
+ $stateSelect.removeProp('disabled').removeClass('disabled').parent('.form-group').removeClass('disabled')
24
+ $stateSelect.find('option').first().text('loading...')
25
+ $stateSelect.load url, ->
26
+ stateSelectAvailable = $(@).find('option:last').val().length > 0
27
+ if stateSelectAvailable
28
+ $(@).prop('required', true)
29
+ $(@).removeProp('disabled')
30
+ else
31
+ $(@).removeProp('required')
32
+ $(@).prop('disabled', true)
33
+
34
+ $(document).on 'change', 'select[data-effective-address-country]', -> loadSubregions($(@))
35
+
36
+ $ -> loadSubregions($('select[data-effective-address-country]'))
37
+ $(document).on 'page:change', -> loadSubregions($('select[data-effective-address-country]'))
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.3.2'.freeze
2
+ VERSION = '1.3.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_addresses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails