Skip to content

Commit

Permalink
Country and State list for new account request form
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaiyanidhi committed Dec 16, 2024
1 parent 0ace33a commit 117f3e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/controllers/country_states_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CountryStatesController < ApplicationController
skip_before_action :authenticate_user!
skip_verify_authorized only: %i[index]

def index
Expand Down
30 changes: 19 additions & 11 deletions app/views/organization_account_requests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

<div class="row">
<div class="col-md-6 mx-auto card p-5">
<div class="col-md-6 mx-auto card p-5" data-controller="country-state">
<%= bootstrap_form_with model: OrganizationAccountRequest.new, url: organization_account_request_path do |form| %>
<% if @organization_account_request.errors.any? %>
<div class="alert alert-danger mt-1" role="alert">
Expand Down Expand Up @@ -66,20 +66,28 @@

<div class="col-lg-6">
<div class="form-group">
<%= form.select :country,
<%= form.select :country,
CS.keys.index_with { |abbr| CS.dig(abbr, :name) }.invert,
{ prompt: "Please select" },
required: true,
class: 'form-control'
%>
{
'data-path': country_states_path,
'data-country-state-target': 'country',
'data-action': 'change->country-state#updateStates',
required: true,
class: 'form-control'
} %>
</div>

<%= form.object.country %>
<div class="form-group">
<%= form.text_field :province_state,
label: t('activerecord.attributes.location.province_state'),
required: true,
class: 'form-control'
%>
<%= 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'
} %>
</div>

<div class="form-group">
Expand Down

0 comments on commit 117f3e2

Please sign in to comment.