effective_addresses 1.11.9 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87c74b7f3991e34ac99e4401f365138341354d8a6264702205bd69a1d45b875f
4
- data.tar.gz: 3f83e9909ccf051881bbeb1f7d2aaa357fead608eb554b2ddf3af3002cd5d963
3
+ metadata.gz: 8df8c437b4b141c75a36c2c0a985c0ca079d6c812135be17a8728899297e02f3
4
+ data.tar.gz: 8f048421f9546067c56acac40fd800b111ee3b185a80d14cfa0d2a9890705c11
5
5
  SHA512:
6
- metadata.gz: 30cd86d88778f8aa624985ad7825340323790fe44a9d8897bbc8801c8d760c7d3e4acba07230c964b6716c2cc45ccb4782a236b136f0f323c723114241932337
7
- data.tar.gz: f227681758c909193a8384d3aa44e08c2eef55ec92505437cca568250347ea99c5760d7d12ae8faa27ec302405543b6d87b9163053bac209f51b3c04b5960fae
6
+ metadata.gz: 666c4fa97777cc00b30429aa60edd72086dfbcceb5d1da7571cf0779209c4dba7b5ccf2ab5e53fe5afcf340541fed815ccc52bc2f3a260b5247c78234b0e42b0
7
+ data.tar.gz: 55afa8e4d582e70e1451bc572ecd54c43c95cfcba426e74fcb3e88f64006f9446f21f0ee45c091d17586f2c0a2f4a052dd9be46b6dedab5c8939ddf5defd7964
data/README.md CHANGED
@@ -159,7 +159,7 @@ The actual permitted parameters are:
159
159
 
160
160
  ### Form Helpers
161
161
 
162
- Use the helper in a Formtastic or SimpleForm form to quickly create the address fields. Currently only supports Formtastic and SimpleForm.
162
+ Use `effective_address_fields` with Effective FormBuilder, SimpleForm, or Formtastic to render address fields.
163
163
 
164
164
  When you select a country from the select input an AJAX GET request will be made to `effective_addresses.address_subregions_path` (`/addresses/subregions/:country_code`)
165
165
  which populates the province/state dropdown with the selected country's states or provinces.
@@ -250,12 +250,10 @@ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
250
250
 
251
251
  ## Testing
252
252
 
253
- The test suite for this gem is unfortunately not yet complete.
253
+ Run the test suite from the gem root:
254
254
 
255
- Run tests by:
256
-
257
- ```ruby
258
- rake spec
255
+ ```console
256
+ bundle exec rake test
259
257
  ```
260
258
 
261
259
  ## Contributing
@@ -1,7 +1,7 @@
1
1
  loadSubregions = ($countrySelect, clearPostalCode = false) ->
2
2
  $.each $countrySelect, (index, countrySelector) ->
3
3
  $particularCountrySelect = $(countrySelector)
4
- countryCode = $particularCountrySelect.val()
4
+ countryCode = $particularCountrySelect.val() || ''
5
5
  uuid = $particularCountrySelect.data('effective-address-country')
6
6
 
7
7
  $nestedFields = $particularCountrySelect.closest('.nested-fields')
@@ -16,34 +16,45 @@ loadSubregions = ($countrySelect, clearPostalCode = false) ->
16
16
  url = "/addresses/subregions/#{countryCode}"
17
17
  $stateSelect = $container.find("select[data-effective-address-state='#{uuid}']:first")
18
18
 
19
+ return unless $stateSelect.length
20
+ prompts = $stateSelect.data('effective-address-prompts') || {}
21
+ fallback = $stateSelect.data('input-js-options')?.placeholder || $stateSelect.find("option[value='']").text()
22
+
19
23
  if countryCode.length == 0
20
24
  $stateSelect.prop('disabled', true).addClass('disabled').parent('.form-group').addClass('disabled').find('label').addClass('disabled')
21
- reinitialize($stateSelect, 'Please choose country first')
25
+ reinitialize($stateSelect, prompts.country_first || fallback)
22
26
  else
23
27
  $stateSelect.removeAttr('disabled').parent('.form-group').removeClass('disabled').find('.disabled').removeClass('disabled')
24
- reinitialize($stateSelect, 'Loading...')
28
+ reinitialize($stateSelect, prompts.loading || fallback)
25
29
 
26
30
  $stateSelect.load url, ->
27
- stateSelectAvailable = $(@).find('option:last').val().length > 0
31
+ stateSelectAvailable = ($(@).find('option:last').val() || '').length > 0
28
32
  if stateSelectAvailable
29
33
  $(@).prop('required', true)
30
34
  $(@).removeAttr('disabled')
31
- reinitialize($stateSelect, 'Please choose', true)
35
+ reinitialize($stateSelect, prompts.choose || fallback, true)
32
36
  else
33
37
  $(@).removeAttr('required')
34
38
  $(@).prop('disabled', true)
35
- reinitialize($stateSelect, 'None exist', true)
39
+ reinitialize($stateSelect, prompts.none || fallback, true)
36
40
 
37
41
  $(document).on 'change', 'select[data-effective-address-country]', -> loadSubregions($(@), true)
38
42
 
39
43
  reinitialize = ($stateSelect, placeholder, keepOptions = false) ->
40
44
  if $stateSelect.hasClass('effective_select') == false
41
- $stateSelect.html("<option value=''>#{placeholder}</option>") unless keepOptions
45
+ $stateSelect.empty() unless keepOptions
46
+ $prompt = $stateSelect.find("option[value='']").first()
47
+ if $prompt.length
48
+ $prompt.text(placeholder)
49
+ else
50
+ $stateSelect.prepend($('<option>').val('').text(placeholder))
51
+ $stateSelect.val('')
42
52
  return
43
53
 
44
54
  $stateSelect.html('') unless keepOptions
55
+ $stateSelect.val('')
45
56
 
46
- opts = $stateSelect.data('input-js-options')
57
+ opts = $stateSelect.data('input-js-options') || {}
47
58
  opts['placeholder'] = placeholder
48
59
  $stateSelect.data('input-js-options', opts)
49
60
 
@@ -8,7 +8,7 @@ module Effective
8
8
  if @subregions.present?
9
9
  render partial: 'effective/addresses/subregions'
10
10
  else
11
- render body: "<option value=''>None Available</option>"
11
+ render html: helpers.content_tag(:option, t('effective_addresses.placeholders.none'), value: '')
12
12
  end
13
13
  end
14
14
  end
@@ -26,6 +26,18 @@ module EffectiveAddressesHelper
26
26
  end
27
27
  end
28
28
 
29
+ def effective_address_state_input_html(uuid)
30
+ {
31
+ 'data-effective-address-state' => uuid,
32
+ 'data-effective-address-prompts' => {
33
+ country_first: t('effective_addresses.placeholders.country_first'),
34
+ loading: t('effective_addresses.placeholders.loading'),
35
+ choose: t('effective_addresses.placeholders.choose'),
36
+ none: t('effective_addresses.placeholders.none')
37
+ }.to_json
38
+ }
39
+ end
40
+
29
41
  def effective_address_pre_select(address)
30
42
  if address.country.blank? && EffectiveAddresses.pre_selected_country.present?
31
43
  address.country = EffectiveAddresses.pre_selected_country
@@ -37,12 +37,12 @@ module Effective
37
37
  validates_format_of :postal_code, :with => POSTAL_CODE_CA,
38
38
  :if => proc { |address| Array(EffectiveAddresses.validate_postal_code_format).include?('CA') && address.country_code == 'CA' },
39
39
  :allow_blank => true, # We're already checking for presence above
40
- :message => 'is an invalid Canadian postal code'
40
+ :message => :invalid_canadian_postal_code
41
41
 
42
42
  validates_format_of :postal_code, :with => POSTAL_CODE_US,
43
43
  :if => proc { |address| Array(EffectiveAddresses.validate_postal_code_format).include?('US') && address.country_code == 'US' },
44
44
  :allow_blank => true, # We're already checking for presence above
45
- :message => 'is an invalid United States zip code'
45
+ :message => :invalid_us_zip_code
46
46
 
47
47
  scope :sorted, -> { order(:updated_at) }
48
48
  scope :billing, -> { where(:category => 'billing') }
@@ -11,7 +11,6 @@
11
11
 
12
12
  - if !skip_same_as_billing && fa.object.category == 'shipping' && f.object.respond_to?(:shipping_address_same_as_billing?)
13
13
  = fa.check_box :shipping_address_same_as_billing,
14
- label: 'Shipping address is same as billing address',
15
14
  required: false,
16
15
  feedback: false,
17
16
  input_html: { checked: same_as_billing }
@@ -23,7 +22,7 @@
23
22
  wrapper: wrapper_options
24
23
 
25
24
  = fa.text_field :address1,
26
- label: (local_assigns[:label] || method.to_s.titleize),
25
+ label: (local_assigns[:label] || f.object.class.human_attribute_name(method, default: method.to_s.titleize)),
27
26
  required: required,
28
27
  disabled: same_as_billing,
29
28
  wrapper: wrapper_options
@@ -50,10 +49,10 @@
50
49
  .row
51
50
  .col-md-4
52
51
  = fa.select :country_code, effective_address_regions_collection(resource: fa.object),
53
- label: 'Country',
54
52
  required: required,
55
53
  disabled: same_as_billing,
56
54
  input_html: { 'data-effective-address-country' => uuid },
55
+ input_js: { placeholder: t('effective_addresses.prompts.select_country') },
57
56
  wrapper: wrapper_options
58
57
 
59
58
  .col-md-5
@@ -61,23 +60,21 @@
61
60
 
62
61
  - if subregions.present?
63
62
  = fa.select :state_code, effective_address_regions_collection(subregions),
64
- label: 'State / Province',
65
63
  required: required,
66
64
  disabled: same_as_billing,
67
- input_html: { 'data-effective-address-state' => uuid },
65
+ input_html: effective_address_state_input_html(uuid),
66
+ input_js: { placeholder: t('effective_addresses.placeholders.choose') },
68
67
  wrapper: wrapper_options
69
68
  - else
70
69
  = fa.select :state_code, [],
71
- label: 'State / Province',
72
70
  required: required,
73
71
  disabled: true,
74
- input_html: { 'data-effective-address-state' => uuid },
75
- input_js: { placeholder: 'Please choose country first' },
72
+ input_html: effective_address_state_input_html(uuid),
73
+ input_js: { placeholder: t('effective_addresses.placeholders.country_first') },
76
74
  wrapper: wrapper_options
77
75
 
78
76
  .col-md-3
79
77
  = fa.text_field :postal_code,
80
- label: 'Postal Code',
81
78
  required: required,
82
79
  disabled: same_as_billing,
83
80
  input_html: { 'data-effective-address-postal-code' => uuid },
@@ -10,10 +10,10 @@
10
10
  - case field
11
11
  - when :full_name
12
12
  - if local_assigns[:use_full_name] || EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
13
- = fa.input :full_name, :required => true, :label => 'Full name', :placeholder => 'Full name'
13
+ = fa.input :full_name, :required => true, :placeholder => t('effective_addresses.placeholders.full_name')
14
14
 
15
15
  - when :address1
16
- = fa.input :address1, :placeholder => 'Address', :label => "Address"
16
+ = fa.input :address1, :placeholder => t('effective_addresses.placeholders.address1'), :label => local_assigns[:label]
17
17
 
18
18
  - when :address2
19
19
  = fa.input :address2, :label => false
@@ -22,34 +22,31 @@
22
22
  = fa.input :address3, :label => false
23
23
 
24
24
  - when :city
25
- = fa.input :city, :placeholder => 'City'
25
+ = fa.input :city, :placeholder => t('effective_addresses.placeholders.city')
26
26
 
27
27
  - when :country_code
28
28
  = fa.input :country_code,
29
29
  :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
30
- :label => 'Country',
31
- :prompt => 'Country...',
30
+ :prompt => t('effective_addresses.prompts.select_country'),
32
31
  :collection => options_for_select(effective_address_regions_collection()),
33
32
  :input_html => { 'data-effective-address-country' => uuid },
34
- :input_js => { placeholder: 'Please choose' }
33
+ :input_js => { placeholder: t('effective_addresses.prompts.select_country') }
35
34
 
36
35
  - when :state_code
37
36
  - if fa.object.country_code.present?
38
37
  = fa.input :state_code,
39
38
  :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
40
- :label => 'Province / State',
41
39
  :collection => options_for_select(effective_address_regions_collection(Carmen::Country.coded(fa.object.country_code).try(:subregions))),
42
- :prompt => 'please select a country',
43
- :input_html => { 'data-effective-address-state' => uuid },
44
- :input_js => { :placeholder => 'Please choose' }
40
+ :prompt => t('effective_addresses.prompts.choose'),
41
+ :input_html => effective_address_state_input_html(uuid),
42
+ :input_js => { :placeholder => t('effective_addresses.placeholders.choose') }
45
43
  - else
46
44
  = fa.input :state_code,
47
45
  :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
48
- :label => 'Province / State',
49
46
  :collection => [],
50
- :prompt => 'please select a country',
51
- :input_html => {:disabled => 'disabled', 'data-effective-address-state' => uuid},
52
- :input_js => { :placeholder => 'Please choose country first' }
47
+ :prompt => t('effective_addresses.prompts.country_first'),
48
+ :input_html => effective_address_state_input_html(uuid).merge(disabled: 'disabled'),
49
+ :input_js => { :placeholder => t('effective_addresses.placeholders.country_first') }
53
50
 
54
51
  - when :postal_code
55
- = fa.input :postal_code, :label => 'Postal / Zip code', :placeholder => 'Postal / Zip code'
52
+ = fa.input :postal_code, :placeholder => t('effective_addresses.placeholders.postal_code')
@@ -9,7 +9,6 @@
9
9
  - if fa.object.category == 'shipping' && f.object.respond_to?(:shipping_address_same_as_billing?)
10
10
  = fa.input :shipping_address_same_as_billing,
11
11
  as: :boolean,
12
- label: 'Shipping address is same as billing address',
13
12
  required: false,
14
13
  input_html: { checked: shipping_address_same_as_billing }
15
14
 
@@ -19,13 +18,15 @@
19
18
  - when :full_name
20
19
  - if local_assigns[:use_full_name] || EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
21
20
  = fa.input :full_name,
21
+ placeholder: t('effective_addresses.placeholders.full_name'),
22
22
  required: required,
23
23
  disabled: shipping_address_same_as_billing,
24
24
  wrapper_html: { style: ('display: none;' if shipping_address_same_as_billing) }
25
25
 
26
26
  - when :address1
27
27
  = fa.input :address1,
28
- label: 'Address',
28
+ label: local_assigns[:label],
29
+ placeholder: t('effective_addresses.placeholders.address1'),
29
30
  required: required,
30
31
  disabled: shipping_address_same_as_billing,
31
32
  wrapper_html: { style: ('display: none;' if shipping_address_same_as_billing) }
@@ -39,6 +40,7 @@
39
40
 
40
41
  - when :city
41
42
  = fa.input :city,
43
+ placeholder: t('effective_addresses.placeholders.city'),
42
44
  required: required,
43
45
  input_html: { 'data-effective-address-city' => uuid },
44
46
  disabled: shipping_address_same_as_billing,
@@ -49,6 +51,8 @@
49
51
  as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
50
52
  required: required,
51
53
  collection: effective_address_regions_collection(),
54
+ prompt: t('effective_addresses.prompts.select_country'),
55
+ input_js: { placeholder: t('effective_addresses.prompts.select_country') },
52
56
  input_html: {'data-effective-address-country' => uuid},
53
57
  disabled: shipping_address_same_as_billing,
54
58
  wrapper_html: { style: ('display: none;' if shipping_address_same_as_billing) }
@@ -59,9 +63,9 @@
59
63
  as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
60
64
  required: required,
61
65
  collection: effective_address_regions_collection(Carmen::Country.coded(fa.object.country_code).try(:subregions)),
62
- prompt: 'Please choose',
63
- input_html: {'data-effective-address-state' => uuid},
64
- input_js: { placeholder: 'Please choose' },
66
+ prompt: t('effective_addresses.prompts.choose'),
67
+ input_html: effective_address_state_input_html(uuid),
68
+ input_js: { placeholder: t('effective_addresses.placeholders.choose') },
65
69
  disabled: shipping_address_same_as_billing,
66
70
  wrapper_html: { style: ('display: none;' if shipping_address_same_as_billing) }
67
71
  - else
@@ -69,14 +73,15 @@
69
73
  as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
70
74
  required: required,
71
75
  collection: [],
72
- prompt: 'Please choose a country first',
73
- input_html: { 'data-effective-address-state' => uuid },
74
- input_js: { placeholder: 'Please choose country first' },
76
+ prompt: t('effective_addresses.prompts.country_first'),
77
+ input_html: effective_address_state_input_html(uuid),
78
+ input_js: { placeholder: t('effective_addresses.placeholders.country_first') },
75
79
  disabled: true,
76
80
  wrapper_html: { style: ('display: none;' if shipping_address_same_as_billing) }
77
81
 
78
82
  - when :postal_code
79
83
  = fa.input :postal_code,
84
+ placeholder: t('effective_addresses.placeholders.postal_code'),
80
85
  required: required,
81
86
  input_html: { 'data-effective-address-postal-code' => uuid },
82
87
  disabled: shipping_address_same_as_billing,
@@ -0,0 +1,41 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ effective/address: Address
5
+ attributes:
6
+ effective/address:
7
+ full_name: Full name
8
+ address1: Address
9
+ address2: Address 2
10
+ address3: Address 3
11
+ city: City
12
+ country_code: Country
13
+ state_code: Province
14
+ postal_code: Postal Code
15
+ shipping_address_same_as_billing: Shipping address is the same as the billing address
16
+ errors:
17
+ models:
18
+ effective/address:
19
+ attributes:
20
+ postal_code:
21
+ invalid_canadian_postal_code: is an invalid Canadian postal code
22
+ invalid_us_zip_code: is an invalid United States zip code
23
+ attributes:
24
+ billing_address: Billing Address
25
+ shipping_address: Shipping Address
26
+ reference_address: Reference Address
27
+ effective_addresses:
28
+ placeholders:
29
+ full_name: Full name
30
+ address1: Address
31
+ city: City
32
+ postal_code: Postal Code
33
+ country_code: Country
34
+ choose: Select...
35
+ country_first: Select a country first...
36
+ loading: Loading...
37
+ none: None available
38
+ prompts:
39
+ choose: Select...
40
+ country_first: Select a country first...
41
+ select_country: Select a country...
@@ -1,26 +1,13 @@
1
1
  en:
2
2
  simple_form:
3
- labels:
4
- defaults:
5
- full_name: Full name
6
- address1: Address 1
7
- address2: Address 2
8
- address3: Address 3
9
- country_code: Country
10
- state_code: Province / State
11
- postal_code: Postal / Zip code
12
-
13
- # hints:
14
- # defaults:
15
-
16
3
  placeholders:
17
4
  defaults:
18
5
  full_name: Full name
19
6
  address1: Address
20
7
  city: City
21
- postal_code: Postal / Zip code
8
+ postal_code: Postal Code
22
9
 
23
10
  prompts:
24
11
  defaults:
25
- country_code: Choose country...
26
- state_code: Please choose country first
12
+ country_code: Select a country...
13
+ state_code: Select a country first...
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.11.9'.freeze
2
+ VERSION = '1.12.0'.freeze
3
3
  end
@@ -1,8 +1,8 @@
1
1
  class EffectiveAddressFullNamePresenceValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
3
  if value.present? && !value.empty? && value.full_name.blank?
4
- record.errors[attribute] << 'is invalid'
5
- value.errors[:full_name] << "can't be blank"
4
+ record.errors.add(attribute, :invalid)
5
+ value.errors.add(:full_name, :blank)
6
6
  end
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  class EffectiveAddressValidValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
3
  if value.present? && !value.empty? && !value.valid?
4
- record.errors[attribute] << 'is invalid'
4
+ record.errors.add(attribute, :invalid)
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_addresses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.9
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
@@ -186,6 +186,7 @@ files:
186
186
  - app/views/effective/addresses/_simple_form.html.haml
187
187
  - app/views/effective/addresses/_subregions.html.haml
188
188
  - config/effective_addresses.rb
189
+ - config/locales/effective_addresses.en.yml
189
190
  - config/locales/simple_form.en.yml
190
191
  - config/routes.rb
191
192
  - db/migrate/101_create_effective_addresses.rb