Commit 1ece2045 authored by Diego de Araújo Martinez Camarinha's avatar Diego de Araújo Martinez Camarinha Committed by marcheing

Dinamically load states according to their countries

Signed-off-by: marcheing's avatarHeitor Reis <[email protected]>
parent 18a2d206
var state_select = function(event) {
$.get('/profiles/states',
{ country: $('select#profile_country :selected').text() },
$.get('/states',
{ country: $('select#profile_country :selected').text(), locale: "<%= I18n.locale %>" },
function(data) { $('div#state_select').html(data); }
);
}
$(document).ready(state_select);
$('select#country').on('change', state_select);
$('select#profile_country').on('change', state_select);
class ProfilesController < ApplicationController
before_action :set_profile, only: [:show, :edit, :update, :destroy]
before_action :set_carmen_locale, only: [:show, :edit, :new]
before_action :set_carmen_locale, only: [:show, :edit, :new, :states]
# GET /profiles
# GET /profiles.json
......
......@@ -74,22 +74,8 @@
</div>
</fieldset>
<fieldset>
<div class="field-label">
<%= f.label "#{t('state')} *", for: 'user-state' %>
</div>
<div class="field-item">
<select id="user-state" name="user-state" required>
<option value="">Selecione o Estado</option>
{{#each brasil-estados}}
<option value="{{ Sigla }}">{{ Nome }}</option>
{{/each}}
</select>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
<div id="state_select">
</div>
<fieldset>
<div class="field-label">
......@@ -254,3 +240,7 @@
</fieldset>
<% end %>
</div>
<% content_for :footer do %>
<%= javascript_include_tag 'profiles/state_select.js' %>
<% end %>
<div class="field">
<%= label_tag I18n.t 'state' %>
<%= select_tag :state, state_select(states) %>
</div><br>
<fieldset>
<div class="field-label">
<%= label_tag 'profile_state', "#{t('state')} *" %>
</div>
<div class="field-item">
<%= select_tag :state, state_select(states) %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
......@@ -9,3 +9,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += %w( profiles/state_select.js )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment