Commit 4a4cf572 authored by Diego de Araújo Martinez Camarinha's avatar Diego de Araújo Martinez Camarinha Committed by marcheing

Add scripts for responsible and school on profile form

Those scripts will render the corresponding fields when the user is
under 18 and if the user is a student.
Signed-off-by: marcheing's avatarHeitor Reis <marcheing@gmail.com>
parent 2944aacb
function responsible_fields(event){
var current_year = new Date().getFullYear();
if(current_year - $('#profile_year').val() < 18) {
$('#responsible_fields').css('display', 'block');
$("#user-responsible-name").prop('required', true);
$("#user-responsible-id-number").prop('required', true);
} else {
$('#responsible_fields').css('display', 'none');
$("#user-responsible-name").prop('required', false);
$("#user-responsible-id-number").prop('required', false);
}
}
$('#profile_year').on('change', responsible_fields);
function school_fields(event){
if($('#student_Yes').is(':checked')) {
$('#school_fields').css('display', 'block');
$("#user-school-type").prop('required', true);
$("#user-school-name").prop('required', true);
} else {
$('#school_fields').css('display', 'none');
$("#user-school-type").prop('required', false);
$("#user-school-name").prop('required', false);
}
}
$('input[name=student]').on('change', school_fields);
......@@ -113,29 +113,31 @@
</div>
</fieldset>
<fieldset class="user-responsible">
<div class="field-label">
<%= f.label "#{t('responsible_name')} *", for: 'user-responsible-name' %>
</div>
<div class="field-item">
<%= f.text_field :responsible_name, id: 'user-responsible-name', 'aria-describedby' => 'passwordHelpText' %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
<fieldset class="user-responsible">
<div class="field-label">
<%= f.label "#{t('responsible_document')} *", for: 'user-responsible-id-number' %>
</div>
<div class="field-item">
<%= f.text_field :responsible_document, id: 'user-responsible-id-number', 'aria-describedby' => 'passwordHelpText' %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
<div id='responsible_fields' style='display:none'>
<fieldset class="user-responsible">
<div class="field-label">
<%= f.label "#{t('responsible_name')} *", for: 'user-responsible-name' %>
</div>
<div class="field-item">
<%= f.text_field :responsible_name, id: 'user-responsible-name', 'aria-describedby' => 'passwordHelpText' %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
<fieldset class="user-responsible">
<div class="field-label">
<%= f.label "#{t('responsible_document')} *", for: 'user-responsible-id-number' %>
</div>
<div class="field-item">
<%= f.text_field :responsible_document, id: 'user-responsible-id-number', 'aria-describedby' => 'passwordHelpText' %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
</div>
<fieldset>
<div class="field-label">
......@@ -161,29 +163,31 @@
</div>
</fieldset>
<fieldset class="user-school">
<div class="field-label">
<%= f.label "#{t('school_type')} *", for: 'user-school-type' %>
</div>
<div id="school_fields" class="field-item" style="display:none">
<%= f.select :school_type, school_type_select %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
<fieldset class="user-school">
<div class="field-label">
<%= f.label I18n.t 'school_name', for: 'user-school-name' %>
</div>
<div class="field-item">
<%= f.text_field :school, id: 'user-school-name' %>
<span class="form-error">
Campo obrigatório.
</span>
</div><br>
</fieldset>
<div id="school_fields" style="display:none">
<fieldset class="user-school">
<div class="field-label">
<%= f.label "#{t('school_type')} *", for: 'user-school-type' %>
</div>
<div class="field-item">
<%= f.select :school_type, school_type_select, id: 'user-school-type' %>
<span class="form-error">
Campo obrigatório.
</span>
</div>
</fieldset>
<fieldset class="user-school">
<div class="field-label">
<%= f.label I18n.t 'school_name', for: 'user-school-name' %>
</div>
<div class="field-item">
<%= f.text_field :school, id: 'user-school-name' %>
<span class="form-error">
Campo obrigatório.
</span>
</div><br>
</fieldset>
</div>
<fieldset>
<div class="field-label">
......@@ -233,5 +237,7 @@
</div>
<% content_for :footer do %>
<%= javascript_include_tag 'profiles/responsible_fields.js' %>
<%= javascript_include_tag 'profiles/school_fields.js' %>
<%= javascript_include_tag 'profiles/state_select.js' %>
<% end %>
......@@ -9,4 +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 )
Rails.application.config.assets.precompile += %w( profiles/*.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