-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1170 - Country State Select Implementation (#1209)
* Removed city-state gem and its dependencies * Implementaion for loading country state from YML * Fix to show selected state value in droplist * Lint fix * Lint fix * Test case fix * Updated code to show country and state list * Controller test for country_state_controller * Lint fix * Lint fix * Lint fix * Country and State list for new account request form * Move location fields to partial * Rename location field partial
- Loading branch information
1 parent
a3073cf
commit 9d0c57d
Showing
17 changed files
with
171 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CountryStatesController < ApplicationController | ||
skip_before_action :authenticate_user! | ||
skip_verify_authorized only: %i[index] | ||
|
||
def index | ||
country = params[:country] | ||
@target = params[:target] | ||
@name = params[:name] | ||
@selected_state = params[:province_state] | ||
|
||
@states = CS[country.to_sym][:states].invert | ||
|
||
respond_to do |format| | ||
format.turbo_stream | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_stream.replace @target do %> | ||
<%= select_tag @name, options_for_select(@states, @selected_state), 'data-country-state-target': 'state', class: 'form-control' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- Country Select --> | ||
<%= form.select :country, | ||
CS.keys.index_with { |abbr| CS.dig(abbr, :name) }.invert, | ||
{ prompt: "Please select" }, | ||
{ | ||
'data-path': country_states_path, | ||
'data-country-state-target': 'country', | ||
'data-action': 'change->country-state#updateStates', | ||
required: true, | ||
class: 'form-control' | ||
} %> | ||
<!-- Province/State Select --> | ||
<%= form.select :province_state, | ||
form.object.country.present? ? | ||
CS.dig(form.object.country.to_sym, :states)&.map { |abbr, name| [:name, abbr] } : [], | ||
{ prompt: "Please select" }, | ||
{ | ||
'data-country-state-target': 'state', | ||
required: true, | ||
class: 'form-control' | ||
} %> | ||
<!-- City/Town Text Field --> | ||
<%= form.text_field :city_town, | ||
required: false, | ||
class: "form-control" %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
US: | ||
name: "United States" | ||
states: | ||
AK: "Alaska" | ||
AL: "Alabama" | ||
AR: "Arkansas" | ||
AZ: "Arizona" | ||
CA: "California" | ||
CO: "Colorado" | ||
CT: "Connecticut" | ||
DC: "District of Columbia" | ||
DE: "Delaware" | ||
FL: "Florida" | ||
GA: "Georgia" | ||
HI: "Hawaii" | ||
IA: "Iowa" | ||
ID: "Idaho" | ||
IL: "Illinois" | ||
IN: "Indiana" | ||
KS: "Kansas" | ||
KY: "Kentucky" | ||
LA: "Louisiana" | ||
MA: "Massachusetts" | ||
MD: "Maryland" | ||
ME: "Maine" | ||
MI: "Michigan" | ||
MN: "Minnesota" | ||
MO: "Missouri" | ||
MS: "Mississippi" | ||
MT: "Montana" | ||
NC: "North Carolina" | ||
ND: "North Dakota" | ||
NE: "Nebraska" | ||
NH: "New Hampshire" | ||
NJ: "New Jersey" | ||
NM: "New Mexico" | ||
NV: "Nevada" | ||
NY: "New York" | ||
OH: "Ohio" | ||
OK: "Oklahoma" | ||
OR: "Oregon" | ||
PA: "Pennsylvania" | ||
RI: "Rhode Island" | ||
SC: "South Carolina" | ||
SD: "South Dakota" | ||
TN: "Tennessee" | ||
TX: "Texas" | ||
UT: "Utah" | ||
VA: "Virginia" | ||
VT: "Vermont" | ||
WA: "Washington" | ||
WI: "Wisconsin" | ||
WV: "West Virginia" | ||
WY: "Wyoming" | ||
CA: | ||
name: "Canada" | ||
states: | ||
AB: "Alberta" | ||
BC: "British Columbia" | ||
MB: "Manitoba" | ||
NB: "New Brunswick" | ||
NL: "Newfoundland and Labrador" | ||
NS: "Nova Scotia" | ||
NT: "Northwest Territories" | ||
NU: "Nunavut" | ||
OT: "Ontario" | ||
PE: "Prince Edward Island" | ||
QC: "Quebec" | ||
SK: "Saskatchewan" | ||
YT: "Yukon" | ||
MX: | ||
name: "Mexico" | ||
states: | ||
AGU: "Aguascalientes" | ||
BCN: "Baja California" | ||
BCS: "Baja California Sur" | ||
CAM: "Campeche" | ||
CHH: "Chihuahua" | ||
CHP: "Chiapas" | ||
CMX: "Mexico City" | ||
COA: "Coahuila" | ||
COL: "Colima" | ||
DUR: "Durango" | ||
GRO: "Guerrero" | ||
GUA: "Guanajuato" | ||
HID: "Hidalgo" | ||
JAL: "Jalisco" | ||
MEX: "México" | ||
MIC: "Michoacán" | ||
MOR: "Morelos" | ||
NAY: "Nayarit" | ||
NLE: "Nuevo León" | ||
OAX: "Oaxaca" | ||
PUE: "Puebla" | ||
QUE: "Querétaro" | ||
ROO: "Quintana Roo" | ||
SIN: "Sinaloa" | ||
SLP: "San Luis Potosí" | ||
SON: "Sonora" | ||
TAB: "Tabasco" | ||
TAM: "Tamaulipas" | ||
TLA: "Tlaxcala" | ||
VER: "Veracruz" | ||
YUC: "Yucatán" | ||
ZAC: "Zacatecas" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
begin | ||
CS = YAML.safe_load_file(Rails.root.join("config/countries_states.yml"), symbolize_names: true).freeze | ||
rescue => e | ||
puts "Error loading countries_states.yml: #{e.message}" | ||
CS = {}.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
test/controllers/states_controller_test.rb → ...rollers/country_states_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.