diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb index b7c6a97..be0af7f 100644 --- a/app/views/plans/new.html.erb +++ b/app/views/plans/new.html.erb @@ -19,7 +19,8 @@ 'data-toggle': 'tooltip', title: _('If applying for funding, state the project title exactly as in the proposal.')) %> -
+
 
+
<%= label_tag(:is_test, raw("#{check_box_tag(:is_test, "1", false)} #{_('mock project for testing, practice, or educational purposes')}")) %>
@@ -27,7 +28,7 @@

<%= _('Select the primary research organisation') %>

-
+
<%= render partial: "shared/accessible_combobox", locals: {name: 'plan[org_name]', id: 'plan_org_name', @@ -38,8 +39,11 @@ error: _('You must select a research organisation from the list.'), tooltip: _('Please select a valid research organisation from the list.')} %>
-
- <%= label_tag(:plan_no_org, raw("#{check_box_tag(:plan_no_org)} #{_('My research organisation is not on the list')} #{_(' or ')} #{_('no research organisation is associated with this plan')}")) %> +
- <%= _('or') %> -
+
+
+ <%= label_tag(:plan_no_org, raw("#{check_box_tag(:plan_no_org)} #{_('My research organisation is not on the list')} #{_(' or ')} #{_('no research organisation is associated with this plan')}")) %> +
@@ -57,8 +61,11 @@ error: _('You must select a funding organisation from the list.'), tooltip: _('Please select a valid funding organisation from the list.')} %>
-
- <%= label_tag(:plan_no_funder, raw("#{check_box_tag(:plan_no_funder)} #{_('No funder associated with this plan')}")) %> +
- <%= _('or') %> -
+
+
+ <%= label_tag(:plan_no_funder, raw("#{check_box_tag(:plan_no_funder)} #{_('No funder associated with this plan')}")) %> +
diff --git a/app/views/shared/_accessible_combobox.html.erb b/app/views/shared/_accessible_combobox.html.erb index 893d185..af6653a 100644 --- a/app/views/shared/_accessible_combobox.html.erb +++ b/app/views/shared/_accessible_combobox.html.erb @@ -5,7 +5,7 @@ <% error = error ||= _('Please select an item from the list.') %> <% json = {} %> - <% models.map{|m| json[m[attribute]] = m.id} %> + <% models.map{|m| json["#{m[attribute]}"] = m.id} %> - + diff --git a/lib/assets/javascripts/utils/autoComplete.js b/lib/assets/javascripts/utils/autoComplete.js index 9391f7b..ff0628f 100644 --- a/lib/assets/javascripts/utils/autoComplete.js +++ b/lib/assets/javascripts/utils/autoComplete.js @@ -15,11 +15,28 @@ if (isObject(crosswalk) && isObject($(idField))) { const json = JSON.parse(`${$(crosswalk).val().replace(/\\"/g, '"').replace(/\\'/g, '\'')}`); const selection = (json[$(el).val()] === undefined ? '' : json[$(el).val()]); - $(el).parent().siblings(`#${idField}`).val(selection); + $(el).parent().siblings(`#${idField}`).val(selection) + .change(); } }; /* + * The accessible autocomplete box escapes characters so we need to decode any valid ones + * so that they appear correctly to the user and are able to be matched to the JSON list + * so we can retrieve the correct org id. + * We only decode certain characters here by design. + */ +const decodeHtml = (el) => { + if (isObject(el)) { + return $(el).val() + .replace(/&/g, '&') + .replace(/'/g, '\'') + .replace(/"/g, '"'); + } + return ''; +}; + +/* * Shows/hides the combobox's clear button based on whether or not text is present * @param the combobox id */ @@ -51,8 +68,10 @@ }, 100); // When the value in the combobox changes update the hidden id field - $(el).on('keyup blur', (e) => { - debounced($(e.currentTarget)); + $(el).on('keyup focus', (e) => { + const txt = $(e.target); + $(txt).val(decodeHtml(txt)); + debounced(txt); }); // Clear the text and hide the button when the user clicks the clear button diff --git a/lib/assets/javascripts/views/plans/new.js b/lib/assets/javascripts/views/plans/new.js index ff19391..6c2d066 100644 --- a/lib/assets/javascripts/views/plans/new.js +++ b/lib/assets/javascripts/views/plans/new.js @@ -97,7 +97,7 @@ }); // Make sure the checkbox is unchecked if we're entering text - $('#new_plan #plan_org_name, #new_plan #plan_funder_name').on('keyup blur', (e) => { + $('#new_plan #plan_org_id, #new_plan #plan_funder_id').change((e) => { const whichOne = $(e.currentTarget).prop('id').split('_')[1]; $(`#plan_no_${whichOne}`).prop('checked', false); handleComboboxChange(); diff --git a/lib/assets/stylesheets/overrides.scss b/lib/assets/stylesheets/overrides.scss index e1d0c01..ec349b1 100644 --- a/lib/assets/stylesheets/overrides.scss +++ b/lib/assets/stylesheets/overrides.scss @@ -408,11 +408,11 @@ top: 0; right: 0; margin-top: 2px; - margin-right: -35px; + margin-right: -28px; border: none; background: transparent; color: $grey; - padding-top: 3px; + padding-top: 4px; font-size: 16pt; } @@ -435,3 +435,14 @@ strong { margin: 0 10px; } } +/* Plan creation */ +.create-plan-or { + padding: 5px 0 0 15px; +} +.create-plan-checkbox { + margin-left: -40px; + margin-top: -5px; +} +.create-plan-mock { + margin-left: -40px; +}