Skip to content

Commit

Permalink
Make requested changes to the copyright and license fields
Browse files Browse the repository at this point in the history
Why these changes are being introduced:

Stakeholders have requested that we preselect the 'author' copyright
value, and make the license field conditionally required when
that copyright value is selected.

Relevant ticket(s):

* [ETD-627](https://mitlibraries.atlassian.net/browse/ETD-627)

How this addresses that need:

This adds the `selected` property to the desired option in
the copyright field. It also updates the `conditionalLicenseField`
function to toggle the `required` property on the license field when
it is shown or hidden.

Side effects of this change:

* Past experience has made me wary of toggling the `required` prop
in this way. However, it is generally reliable under a single
binary condition (either the 'Author' copyright value is selected,
or it isn't). I haven't noticed any issues in click-testing.
* `selected` is tied to a value, so in this case we are preselecting
the first option. This corresponds to 'Author' in both staging and
prod, but it would be better to make an explicit association. If
the data were to change order somehow, the wrong copyright holder
could be preselected.
  • Loading branch information
jazairi committed Dec 6, 2024
1 parent 694d3e5 commit 86836ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/student_thesis_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ function conditionalLicenseField() {
var value = $("select#thesis_copyright_id option:selected").text();
if ('I hold copyright' == value) {
$("div.thesis_license").show();
$("select#thesis_license_id").prop('required', true);
} else {
$("div.thesis_license").hide();
$("select#thesis_license_id")[0].value = "";
$("select#thesis_license_id").prop('required', false);
}
};

Expand Down
1 change: 1 addition & 0 deletions app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Thesis < ApplicationRecord

VALIDATION_MSGS = {
copyright: 'Required - Please identify the copyright holder.',
license: 'Required - Please identify the license type.',
graduation_year: 'Required - Please input your year of graduation.',
graduation_month: 'Required - Please select your month of graduation.',
departments: 'Required - Please select your primary department.',
Expand Down
6 changes: 4 additions & 2 deletions app/views/thesis/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
</div>

<%= f.association :copyright, as: :select,
selected: 1,
required: true,
collection: Copyright.display_to_author,
validate: { presence: true },
Expand All @@ -140,12 +141,13 @@

<%= f.association :license, as: :select,
include_hidden: false,
label: 'License (if you retain copyright)',
label: 'License (if you retain copyright) *',
label_method: :display_description,
label_html: { class: 'col1q' },
wrapper_html: { class: 'field-row select layout-1q3q layout-band' },
input_html: { class: 'field field-select col3q', multiple: false,
aria: { describedby: 'thesis_license-hint' } },
aria: { describedby: 'thesis_license-hint' },
data: { msg: Thesis::VALIDATION_MSGS[:license] } },
hint: 'Not sure what to select? Learn more about <a href="https://chooser-beta.creativecommons.org/" target="_blank">Creative Commons licenses</a>.'.html_safe,
hint_html: { class: 'col3q', id: 'thesis_license-hint' } %>

Expand Down

0 comments on commit 86836ca

Please sign in to comment.