country_state_select 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.md +94 -26
- data/lib/country_state_select/version.rb +1 -1
- data/test/dummy/Gemfile +1 -1
- data/test/dummy/app/assets/javascripts/application.js +1 -0
- data/test/dummy/app/assets/javascripts/users.js.coffee +9 -3
- data/test/dummy/app/assets/stylesheets/application.css +1 -0
- data/test/dummy/app/views/users/_form.html.erb +2 -4
- data/test/dummy/app/views/users/index.html.erb +1 -1
- data/test/dummy/app/views/users/show.html.erb +1 -1
- data/vendor/assets/javascript/country_state_select.js.erb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2NlYzIwZGViOWMxMzM2ZjNmODAzZGI2MTY2Y2Y5MGRjNTE4NzU3Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDFmZmJhYjk5YTE1ZTZjZDNhMGMxNDg2MDM3MmU5MzRkZjQwMWE3Mg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2NhNTMwYTQxMWMwNWM0NDNiZTIwOThlMzAyOTZlMjQ5NzkyMmE2Yzk4YWJk
|
10
|
+
NzM2NGU2OWIzNjI3ZWYxMWMyNjU3MDc4ZmY2YWU0MmU3ZDI1YTQxZjM1OGE5
|
11
|
+
Y2VhMWY0NDcyNTc5MDBlZmMyOTYzMDczMjVhMDJmZGFkNDc0MGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDFjNGU4MTRjNmY2MWU4YzE1NDBkMTNkZGM5NzA5ODgwZjE1MDliMzIwM2Yz
|
14
|
+
NTUyZTZiYjNiMjBjMDIyMGY2M2M4NzNhNDBlMWUxNjZmMDJiZGNjMTNkOWVl
|
15
|
+
OWY4YjBkMzQ1YjUwZjY4MWM4NTQ1NTE4NDk4MDgxMjFlZmRjN2Y=
|
data/README.md
CHANGED
@@ -1,52 +1,120 @@
|
|
1
|
-
|
1
|
+
##Country State Select
|
2
2
|
|
3
|
+
Country State Select is library which gives you all the country names and when you select any country then it also create the other select box with all the states name of that country
|
3
4
|
|
4
|
-
|
5
|
+
#Getting Started
|
5
6
|
|
6
|
-
|
7
|
+
Country State Select is released as a Ruby Gem. The gem is to be installed within a Ruby
|
8
|
+
or Rails application. To install, simply add the following to your Gemfile:
|
7
9
|
|
8
10
|
gem 'country_state_select'
|
11
|
+
|
12
|
+
Run bundle install and don't forget to restart your server after you install a new gem.
|
13
|
+
|
14
|
+
##Usage
|
15
|
+
|
16
|
+
It returns all the country name
|
17
|
+
|
18
|
+
CountryStateSelect::Constant::COUNTRIES
|
19
|
+
|
20
|
+
=> ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
|
21
|
+
"Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
|
22
|
+
................................]
|
23
|
+
|
24
|
+
It returns all the Indian states.
|
25
|
+
|
26
|
+
CountryStateSelect::Constant::INDIAN_STATES
|
27
|
+
|
28
|
+
It return all the USA states.
|
29
|
+
|
30
|
+
CountryStateSelect::Constant::USA_STATES
|
31
|
+
|
32
|
+
It returns all the Canadian states.
|
33
|
+
|
34
|
+
CountryStateSelect::CANADIAN_STATES
|
35
|
+
|
36
|
+
It returns all the UK states.
|
37
|
+
|
38
|
+
CountryStateSelect::UK_STATES
|
9
39
|
|
10
|
-
|
40
|
+
##Version History
|
11
41
|
|
12
|
-
|
42
|
+
1.0.0
|
43
|
+
|
44
|
+
It is the stable version which have all the feature
|
45
|
+
It also have support of chosen-rails
|
13
46
|
|
14
|
-
|
47
|
+
0.0.3 & 0.0.4
|
15
48
|
|
16
|
-
|
49
|
+
In both the version state field will not update if you will select the country
|
17
50
|
|
18
51
|
|
19
52
|
##Very easy to create select box just follow below steps
|
20
53
|
|
21
|
-
First put this to the application.js file to load the js file
|
22
|
-
|
23
|
-
|
54
|
+
First put this to the application.js file to load the js file
|
55
|
+
|
56
|
+
//= require country_state_select
|
57
|
+
|
58
|
+
It will create for you a select option, just care about 'id' if you want to update your state field
|
59
|
+
|
60
|
+
<%= f.select :country_name, CountryStateSelect::Constant::COUNTRIES, {}, id: 'country_id' %>
|
61
|
+
|
62
|
+
Create your state like mention below, and take care about id of the select field if you will change this then it will now work as it should be
|
63
|
+
|
64
|
+
<%= f.text_field :state_name ,:id=> 'state_name'%>
|
65
|
+
|
66
|
+
If you want to store country id then use this select option it will store the country id inside the database if you want the state field update with this then you can put id field inside this also like we have mention in previous example
|
67
|
+
|
68
|
+
<%= f.select(:country_id, options_for_select(Array[*CountryStateSelect::Constant::COUNTRIES.collect {|v,i| [v,
|
69
|
+
CountryStateSelect::Constant::COUNTRIES.index(v)] }], :selected => f.object)) %>
|
24
70
|
|
25
|
-
|
71
|
+
If you want to fetch the country name By 'id' then you have to just write
|
26
72
|
|
27
|
-
|
73
|
+
<%= CountryStateSelect::Constant::COUNTRIES['PASS THE COUNTRY ID WHICH YOU SAVE HERE'] %>
|
28
74
|
|
29
|
-
Create your state like mention below, and take care about id of the select field if you will change this then it will now work as it should be
|
30
75
|
|
31
|
-
|
76
|
+
NOTE :- It will update the state field when there will be India,United Kingdom,Canada and United States so except these country if you select other country then you have to manually enter the state name, we are working on this soon we will cover most of the country
|
77
|
+
|
78
|
+
##Configure if want country_state_select with chosen_rails
|
32
79
|
|
33
|
-
|
80
|
+
Include both the gem in your Gemfile
|
81
|
+
gem 'chosen-rails'
|
82
|
+
gem 'country_state_select'
|
83
|
+
|
84
|
+
Include 'chosen-jquery' inside your application.js file
|
85
|
+
//= require chosen-jquery
|
34
86
|
|
35
|
-
|
36
|
-
|
87
|
+
Include chosen inside stylesheet assets
|
88
|
+
*= require chosen
|
37
89
|
|
38
|
-
|
90
|
+
Enable chosen javascript
|
39
91
|
|
40
|
-
|
92
|
+
Create one coffee-script file eg scaffold.js.coffee
|
93
|
+
$(document).on 'ready page:load', ->
|
94
|
+
$('.chosen-select').change ->
|
95
|
+
if $('#state_name option').size() > 1
|
96
|
+
$("#state_name" ).chosen() //this will add the chosen-select in to the state select
|
97
|
+
$("#state_name_chosen").empty();
|
98
|
+
|
99
|
+
$('.chosen-select').chosen
|
100
|
+
allow_single_deselect: true
|
101
|
+
no_results_text: 'No results matched'
|
102
|
+
width: '280px'
|
41
103
|
|
104
|
+
And this file must be included in application.js
|
105
|
+
//= require chosen-jquery
|
106
|
+
//= require scaffold
|
107
|
+
above scaffold is required because we have put the js inside that if you put in other coffee file that that you have to include
|
42
108
|
|
43
|
-
|
109
|
+
And the country select option will be
|
110
|
+
<%= f.select :country_name, CountryStateSelect::Constant::COUNTRIES, {}, id: 'country_id', :class=>'chosen-select' %>
|
111
|
+
And the state input box will be
|
112
|
+
<%= f.text_field :state_name ,:id=>'state_name' %>
|
44
113
|
|
114
|
+
##Contributing to Country State Select
|
45
115
|
|
46
|
-
|
116
|
+
Fork, fix, then send me a pull request.
|
117
|
+
|
118
|
+
##License
|
47
119
|
|
48
|
-
|
49
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
-
5. Create a new Pull Request
|
120
|
+
:include:license
|
data/test/dummy/Gemfile
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
1
|
+
$(document).on 'ready page:load', ->
|
2
|
+
$('.chosen-select').change ->
|
3
|
+
if $('#state_name option').size() > 1
|
4
|
+
$("#state_name" ).chosen() //this will add the chosen-select in to the state select
|
5
|
+
$("#state_name_chosen").empty();
|
6
|
+
$('.chosen-select').chosen
|
7
|
+
allow_single_deselect: true
|
8
|
+
no_results_text: 'No results matched'
|
9
|
+
width: '280px'
|
@@ -21,10 +21,8 @@
|
|
21
21
|
</div>
|
22
22
|
<div class="field">
|
23
23
|
<%= f.label :country_id %><br>
|
24
|
-
<%= f.select :country_name, CountryStateSelect::Constant::COUNTRIES, {}, id: 'country_id' %>
|
25
|
-
|
26
|
-
<!---I have not taken the country_id in below select due to not repeat the two same id-->
|
27
|
-
<%= f.select(:country_id, options_for_select(Array[*CountryStateSelect::Constant::COUNTRIES.collect {|v,i| [v,CountryStateSelect::Constant::COUNTRIES.index(v)] }], :selected => f.object)) %>
|
24
|
+
<%= f.select :country_name, CountryStateSelect::Constant::COUNTRIES, {}, id: 'country_id', :class=>'chosen-select' %>
|
25
|
+
|
28
26
|
</div>
|
29
27
|
<div class="field">
|
30
28
|
<%= f.label :state_name %><br>
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<tr>
|
20
20
|
<td><%= user.name %></td>
|
21
21
|
<td><%= user.email %></td>
|
22
|
-
<td
|
22
|
+
<td><%#= CountryStateSelect::Constant::COUNTRIES[user.country_id] %></td>
|
23
23
|
<td><%= user.country_name%></td>
|
24
24
|
<td><%= user.state_name %></td>
|
25
25
|
<td><%= link_to 'Show', user %></td>
|
@@ -3,7 +3,7 @@ $(document).on('ready page:load', function () {
|
|
3
3
|
var default_state = []
|
4
4
|
var country = $('#country_id option:selected').text()
|
5
5
|
var name = $("#state_name").attr("name");
|
6
|
-
var select = $('<select name='+ name +' id="
|
6
|
+
var select = $('<select name='+ name +' id="state_name"></select>');
|
7
7
|
var indian_state =
|
8
8
|
<%= CountryStateSelect::Constant::INDIAN_STATES %>
|
9
9
|
var usa_state =
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: country_state_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arvind Vyas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Can list out country and according to that can list stae.
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
-
|
62
|
+
- .gitignore
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
@@ -155,12 +155,12 @@ require_paths:
|
|
155
155
|
- lib
|
156
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- -
|
158
|
+
- - ! '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- -
|
163
|
+
- - ! '>='
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|