Skip to content

Commit

Permalink
Add form validations (#1588)
Browse files Browse the repository at this point in the history
removed formtastic

added required asterisks to create plan page and updated JS logic of Org selection

added namespaces to edit profile, sign in and create account forms to fix duplicate id issue

fixed JS behind links and their validation

fixed JS behind links and their validation

removed console.log statement and added rake tasks for data validation cleanup

Add form validations

removed formtastic

added required asterisks to create plan page and updated JS logic of Org selection

added namespaces to edit profile, sign in and create account forms to fix duplicate id issue

fixed JS behind links and their validation

fixed JS behind links and their validation

removed console.log statement and added rake tasks for data validation cleanup

made recommended adjustments

reverted schema.rb

removed unecessary other_org query
  • Loading branch information
briri authored and xsrust committed Jun 13, 2018
1 parent 84ca8f6 commit f525dac
Show file tree
Hide file tree
Showing 27 changed files with 215 additions and 165 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -46,7 +46,6 @@ gem 'ledermann-rails-settings'
gem 'contact_us' # COULD BE EASILY REPLACED WITH OUR OWN CODE
gem 'recaptcha'
gem 'dragonfly' # LOGO UPLOAD
gem 'formtastic'

# ------------------------------------------------
# EXPORTING
Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Expand Up @@ -84,8 +84,6 @@ GEM
loofah (>= 2.0)
sax-machine (>= 1.0)
flag_shih_tzu (0.3.19)
formtastic (3.1.5)
actionpack (>= 3.2.13)
gettext (3.2.9)
locale (>= 2.0.5)
text (>= 1.3.0)
Expand Down Expand Up @@ -257,7 +255,6 @@ DEPENDENCIES
dragonfly
feedjira
flag_shih_tzu
formtastic
gettext
gettext_i18n_rails
gettext_i18n_rails_js
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -161,7 +161,7 @@ def acknowledge_notification

private
def org_swap_params
params.require(:superadmin_user).permit(:org_id, :org_name)
params.require(:user).permit(:org_id, :org_name)
end

##
Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/registrations/_personal_details.html.erb
@@ -1,4 +1,4 @@
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, id: 'personal_details_registration_form' }) do |f| %>
<%= form_for(resource, namespace: current_user.id, as: resource_name, url: registration_path(resource_name), html: {method: :put, id: 'personal_details_registration_form' }) do |f| %>
<p class="form-control-static">
<%= raw _("Please note that your email address is used as your username. If you change this, remember to use your new email address on sign in.") %>
</p>
Expand All @@ -24,7 +24,7 @@

<% org_admin = (current_user.can_org_admin? && !current_user.can_super_admin?) %>
<div class="form-group col-xs-8" id="org-controls" <%= raw "data-toggle=\"tooltip\" title=\"#{_('Changing your organisation will result in the loss of your administrative privileges.')}\"" if org_admin %>>
<%= render partial: "shared/my_org", locals: {f: f, default_org: @default_org, orgs: @orgs, allow_other_orgs: true} %>
<%= render partial: "shared/my_org", locals: {f: f, default_org: @default_org, orgs: @orgs, allow_other_orgs: true, required: true} %>
</div>
<% if org_admin %>
<input type="hidden" id="original_org" value="<%= @user.org_id %>">
Expand Down
4 changes: 2 additions & 2 deletions app/views/org_admin/templates/_form.html.erb
Expand Up @@ -51,7 +51,7 @@
<% end %>
<% if template.org.funder? %>
<div class="form-group col-xs-8">
<div class="col-xs-8">
<%= render(partial: '/shared/links',
locals: {
context: 'funder',
Expand All @@ -60,7 +60,7 @@
max_number_links: MAX_NUMBER_LINKS_FUNDER,
tooltip: _('Add links to funder websites that provide additional information about the requirements for this template') }) %>
</div>
<div class="form-group col-xs-8">
<div class="col-xs-8">
<%= render(partial: '/shared/links',
locals: {
context: 'sample_plan',
Expand Down
4 changes: 2 additions & 2 deletions app/views/orgs/_profile_form.html.erb
Expand Up @@ -31,7 +31,7 @@
</div>

<div class="row">
<div class="form-group col-xs-8">
<div class="col-xs-8">
<%= render(partial: '/shared/links',
locals: {
context: 'org',
Expand All @@ -51,7 +51,7 @@
<div class="row">
<div class="form-group col-xs-4">
<%= f.label :contact_email, _('Contact email'), class: "control-label" %>
<%= f.text_field :contact_email, class: "form-control" %>
<%= f.text_field :contact_email, class: "form-control", 'aria-required': true %>
</div>
<div class="form-group col-xs-4">
<%= f.label :contact_name, _('Link text'), class: "control-label" %>
Expand Down
29 changes: 20 additions & 9 deletions app/views/orgs/admin_edit.html.erb
Expand Up @@ -20,18 +20,29 @@
</li>
<% end %>
</ul>


<!-- render navigation tabs for the template-->
<div class="tab-content">
<div id="profile" role="tabpanel" class="tab-pane active px-2">
<%= render partial: 'orgs/profile_form', locals: local_assigns %>
<div role="tabpanel" class="tab-pane active" id="profile">
<div class="panel panel-default">
<div class="panel-body">
<div class="px-2">
<%= render partial: 'orgs/profile_form', locals: local_assigns %>
</div>
</div>
</div>
</div>

<% if org.id.present? %>
<div id="feedback" role="tabpanel" class="tab-pane">
<%= render partial: 'orgs/feedback_form', locals: local_assigns %>
<div role="tabpanel" class="tab-pane" id="feedback">
<div class="panel panel-default">
<div class="panel-body">
<% if org.id.present? %>
<div>
<%= render partial: 'orgs/feedback_form', locals: local_assigns %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>

2 changes: 1 addition & 1 deletion app/views/orgs/shibboleth_ds.html.erb
Expand Up @@ -7,7 +7,7 @@

<div class="row">
<div class="col-md-12">
<%= form_for 'shibboleth_ds', url: shibboleth_ds_path, html: {id: 'shibboleth_ds'} do |f| %>
<%= form_for 'shibboleth_ds', url: shibboleth_ds_path, namespace: 'shib-ds', html: {id: 'shibboleth_ds'} do |f| %>
<div class="form-group col-xs-8">
<%= f.label(:org_name, _('Look up your organisation here'), class: "control-label") %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/plans/new.html.erb
Expand Up @@ -13,7 +13,7 @@
<div class="col-md-12">
<%= form_for Plan.new, url: plans_path do |f| %>
<!-- Plan name section -->
<h2 id="project-title"><%= _('What research project are you planning?') %></h2>
<h2 id="project-title"><span class="red" title="<%= _('This field is required.') %>">* </span><%= _('What research project are you planning?') %></h2>
<div class="form-group row">
<div class="col-xs-6">
<%= f.text_field(:title, class: 'form-control', 'aria-describedby': 'project-title', 'aria-required': 'true', 'aria-label': 'project-title',
Expand All @@ -27,7 +27,7 @@
</div>

<!-- Organisation selection -->
<h2 id="research-org"><%= _('Select the primary research organisation') %></h2>
<h2 id="research-org"><span class="red" title="<%= _('You must select a research organisation from the list or click the checkbox.') %>">* </span><%= _('Select the primary research organisation') %></h2>
<div class="form-group row">
<div class="col-md-6">
<%= render partial: "shared/accessible_combobox",
Expand All @@ -50,7 +50,7 @@
</div>

<!-- Funder selection -->
<h2 id="funder-org"><%= _('Select the primary funding organisation') %></h2>
<h2 id="funder-org"><span class="red" title="<%= _('You must select a funder from the list or click the checkbox.') %>">* </span><%= _('Select the primary funding organisation') %></h2>
<div class="form-group row">
<div class="col-xs-6">
<%= render partial: "shared/accessible_combobox",
Expand Down
5 changes: 3 additions & 2 deletions app/views/shared/_accessible_combobox.html.erb
Expand Up @@ -6,7 +6,8 @@
<% json = {} %>
<% models.map{|m| json["#{m[attribute]}"] = m.id} %>

<!-- If the incoming name has a namespace prefix, remove it so that the controller can access the params -->
<% name = name.gsub(name.match(/^.*\[/)[0].split('_')[0] + '_', '') %>
<input type="text" name="<%= name %>" id="<%= id %>"
class="js-combobox form-control <%= classes %>" list="<%= id %>_list"
placeholder="<%= _('Begin typing to see a filtered list') %>"
Expand All @@ -32,7 +33,7 @@
<!-- the selected id is found after the combobox loses focus by finding the selected item in the crosswalk json -->
<input type="hidden" id="<%= id.gsub("_#{attribute}", "_id") %>" name="<%= name.gsub("_#{attribute}]", "_id]") %>"
value="<%= default_selection.id unless default_selection.nil? %>" aria-required="<%= required %>"
data-validation="js-combobox" data-validation-error="<%= error %>" />
class="org-id" data-validation="js-combobox" data-validation-error="<%= error %>" />

<% else %>
<span id="<%= id %>_no_items"><%= _('No items available.') %></span>
Expand Down
5 changes: 3 additions & 2 deletions app/views/shared/_create_account_form.html.erb
@@ -1,4 +1,4 @@
<%= form_for resource, as: 'user', url: registration_path("user"), html: {autocomplete: "off", id: "create_account_form"} do |f| %>
<%= form_for resource, as: 'user', namespace: 'new_user', url: registration_path("user"), html: {autocomplete: "off", id: "create_account_form"} do |f| %>

<div class="form-group">
<%= f.label(:firstname, _('First Name'), class: "control-label") %>
Expand All @@ -15,7 +15,8 @@
<div class="form-group">
<%= render partial: "shared/my_org",
locals: {f: f, default_org: @default_org,
orgs: Org.where("parent_id IS NULL").order("sort_name ASC, name ASC"), allow_other_orgs: true} %>
orgs: Org.where("parent_id IS NULL").order("sort_name ASC, name ASC"),
allow_other_orgs: true, required: true} %>
</div>

<div class="form-group">
Expand Down
8 changes: 4 additions & 4 deletions app/views/shared/_links.html.erb
Expand Up @@ -20,15 +20,15 @@
<% links.each_with_index do |l, i| %>
<div class="link row">
<div class="col-xs-5">
<div class="form-group">
<div class="form-group link-input">
<%= label_tag "link_link#{i}", _('URL'), class: "control-label" %>
<%= text_field_tag 'link_link', l['link'], class: "form-control", id: "link_link#{i}", 'data-validation': 'url' %>
<%= text_field_tag 'link_link', l['link'], class: "form-control", id: "#{context}_link_link#{i}", 'data-validation': 'url', 'aria-required': true %>
</div>
</div>
<div class="col-xs-5">
<div class="form-group">
<div class="form-group link-input">
<%= label_tag "link_text#{i}", _('Link text'), class: "control-label" %>
<%= text_field_tag 'link_text', l['text'], class: "form-control", id: "link_text#{i}", 'aria-required': true %>
<%= text_field_tag 'link_text', l['text'], class: "form-control", id: "#{context}link_text#{i}", 'aria-required': true %>
</div>
</div>
<div class="col-xs-2">
Expand Down
14 changes: 8 additions & 6 deletions app/views/shared/_my_org.html.erb
@@ -1,21 +1,23 @@
<% required = required ||= false %>
<% other_org = Org.find_by(is_other: true) %>
<%= f.label :org_name, _('Organisation'), class: 'control-label' %>
<% object_name = (f.options[:namespace].present? ? "#{f.options[:namespace]}_#{f.object_name}" : f.object_name) %>
<%= render partial: "shared/accessible_combobox",
locals: {name: "#{object_name}[org_name]",
id: "#{object_name}_org_name",
default_selection: default_org,
models: orgs,
attribute: 'name'} %>
attribute: 'name',
error: _('Please select an organisation from the list, or click the "My organisation isn\'t listed" link and enter your organisation\'s name.'),
required: required} %>
<% if allow_other_orgs %>
<div class="clearfix"></div>
<a href="#" id="other-org-link"><%= _('My organisation isn\'t listed.') %></a>
<%= f.hidden_field :other_org_id, value: other_org.present? ? other_org.id : '' %>
<a href="#" class="other-org-link"><%= _('My organisation isn\'t listed.') %></a>

<div class="clearfix"></div>
<%= f.text_field :other_organisation, autocomplete: "off", class: "form-control hide",
<%= f.text_field :other_organisation, autocomplete: "off", class: "form-control hide other-org",
placeholder: _('Please enter the name of your organisation'),
"aria-label": "other_organisation" %>
<div class="form-group has-error">
<span id="help-org" class="help-block" style="display:none"><%= _('Please select an organisation from the list, or enter your organisation\'s name.') %></span>
</div>
<% end %>
6 changes: 3 additions & 3 deletions app/views/shared/_sign_in_form.html.erb
@@ -1,11 +1,11 @@
<%= form_for resource, as: 'user', url: user_session_path, html: {id: "sign_in_form"} do |f| %>
<%= form_for resource, as: 'user', namespace: 'signin', url: user_session_path, html: {id: "sign_in_form"} do |f| %>
<div class="form-group">
<%= f.label(:email, _('Email'), class: 'control-label') %>
<%= f.email_field(:email, class: 'form-control', "aria-required": true, id: nil) %>
<%= f.email_field(:email, class: 'form-control', "aria-required": true) %>
</div>
<div class="form-group">
<%= f.label(:password, _('Password'), class: 'control-label') %>
<%= f.password_field(:password, class: 'form-control', "aria-required": true, id: nil) %>
<%= f.password_field(:password, class: 'form-control', "aria-required": true) %>
</div>
<div>
<%= link_to _('Forgot password?'), new_password_path('user') %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/super_admin/users/edit.html.erb
Expand Up @@ -27,7 +27,7 @@
</div>

<div class="form-group col-xs-8" id="org-controls">
<%= render partial: "shared/my_org", locals: {f: f, default_org: default_org, orgs: orgs, allow_other_orgs: true} %>
<%= render partial: "shared/my_org", locals: {f: f, default_org: default_org, orgs: orgs, allow_other_orgs: true, required: true} %>
</div>

<% if MANY_LANGUAGES %>
Expand Down
79 changes: 0 additions & 79 deletions config/initializers/formtastic.rb

This file was deleted.

0 comments on commit f525dac

Please sign in to comment.