country_state_select 3.0.0 → 3.0.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc1e45ac3197072daa429452d164001f6e29ae40
|
4
|
+
data.tar.gz: 4faff126bd82fd8a8a4f15305dfdaff2ba8921ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72674f4b8ca1ba0becb2a7df2b4db2e48415ffaa89e815145de07c498a4d5d24977580c9ea64a6c3d427e6b2336ff9ebfd3c03cf986dad0f867587b54e05ce3b
|
7
|
+
data.tar.gz: c9ccee4383931e5d2e8cca3845afb36d0db02c7a2b198d3b3c71dd83eea2d171d6bf17ee18dde8f78f012f23a5f00854b1cc939740afb8c910a5c7168b1643c9
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["arvindvyas07@gmail.com"]
|
11
11
|
spec.summary = %q{Dynamically select Country and State.}
|
12
12
|
spec.description = %q{Country State Select is a Ruby Gem that aims to make Country and State/Province selection a cinch in Ruby on Rails environments.}
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/arvindvyas/Country-State-Select"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/country_state_select.rb
CHANGED
@@ -25,6 +25,13 @@ module CountryStateSelect
|
|
25
25
|
states
|
26
26
|
end
|
27
27
|
|
28
|
+
#Return either the City (String) or Cities (Array)
|
29
|
+
def self.cities_collection(f, options)
|
30
|
+
cities = collect_cities(f.object.send(options[:state]))
|
31
|
+
cities
|
32
|
+
end
|
33
|
+
|
34
|
+
|
28
35
|
#Return the collected States for a given Country
|
29
36
|
def self.collect_states(country)
|
30
37
|
CS.states(country).collect {|p| [ p[1], p[0] ] }.compact
|
@@ -32,7 +39,11 @@ module CountryStateSelect
|
|
32
39
|
|
33
40
|
#Return the cities of given state and country
|
34
41
|
def self.collect_cities(state_id = '', country_id = '')
|
35
|
-
|
42
|
+
if state_id.nil? || country_id.nil?
|
43
|
+
[]
|
44
|
+
else
|
45
|
+
CS.cities(state_id.to_sym, country_id.to_sym)
|
46
|
+
end
|
36
47
|
end
|
37
48
|
|
38
49
|
#Return a hash for use in the simple_form
|
@@ -43,6 +54,13 @@ module CountryStateSelect
|
|
43
54
|
options
|
44
55
|
end
|
45
56
|
|
57
|
+
def self.city_options(options)
|
58
|
+
cities = cities_collection(options[:form], options[:field_names])
|
59
|
+
options = options.merge(collection: cities)
|
60
|
+
options = options.merge(:as => :string) if cities.class == String
|
61
|
+
options
|
62
|
+
end
|
63
|
+
|
46
64
|
end
|
47
65
|
|
48
66
|
case ::Rails.version.to_s
|
@@ -3,8 +3,7 @@
|
|
3
3
|
<%= f.input :test_country, label: "Country", collection: CountryStateSelect.countries_collection %>
|
4
4
|
|
5
5
|
<%= f.input :test_state, CountryStateSelect.state_options(label: "State / Province", form: f, field_names: { :country => :test_country, :state => :home_state } ) %>
|
6
|
-
|
7
|
-
<%= f.input :test_city, label: "State / Province" %>
|
6
|
+
<%= f.input :test_city, CountryStateSelect.city_options(label: "City ", form: f, field_names: { :state => :test_state, :city => :home_city } ) %>
|
8
7
|
|
9
8
|
<br /><br />
|
10
9
|
|
@@ -14,7 +14,6 @@ function CountryStateSelect(options) {
|
|
14
14
|
return statesDropdown();
|
15
15
|
|
16
16
|
// ====== ***** METHODS ***** ===================================================================== //
|
17
|
-
|
18
17
|
function statesDropdown() {
|
19
18
|
|
20
19
|
addChosenToCountry();
|
@@ -63,6 +62,7 @@ function CountryStateSelect(options) {
|
|
63
62
|
function removeChosenFromFields(){
|
64
63
|
if (chosenIsRequired) {
|
65
64
|
$("#" + options['state_id'] + "_chosen").remove();
|
65
|
+
$("#" + options['city_id'] + "_chosen").remove();
|
66
66
|
}
|
67
67
|
}
|
68
68
|
|
@@ -80,6 +80,7 @@ function CountryStateSelect(options) {
|
|
80
80
|
|
81
81
|
//Remove all Chosen from existing fields
|
82
82
|
removeChosenFromFields();
|
83
|
+
findCities('','')
|
83
84
|
|
84
85
|
//Perform AJAX request to get the data; on success, build the dropdown
|
85
86
|
$.ajax({
|
@@ -127,6 +128,7 @@ function CountryStateSelect(options) {
|
|
127
128
|
html += '</select>';
|
128
129
|
}
|
129
130
|
|
131
|
+
|
130
132
|
$('#' + state_id).replaceWith(html);
|
131
133
|
|
132
134
|
//This has to happen AFTER we've replaced the dropdown or text
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: country_state_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arvind Vyas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -227,7 +227,7 @@ files:
|
|
227
227
|
- test/dummy/vendor/assets/javascripts/.keep
|
228
228
|
- test/dummy/vendor/assets/stylesheets/.keep
|
229
229
|
- vendor/assets/javascript/country_state_select.js.erb
|
230
|
-
homepage: https://github.com/
|
230
|
+
homepage: https://github.com/arvindvyas/Country-State-Select
|
231
231
|
licenses:
|
232
232
|
- MIT
|
233
233
|
metadata: {}
|