Skip to content

Commit 671efa1

Browse files
committed
Make requested changes to the copyright and license fields
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.
1 parent 694d3e5 commit 671efa1

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

app/assets/javascripts/student_thesis_form.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ function conditionalLicenseField() {
66
var value = $("select#thesis_copyright_id option:selected").text();
77
if ('I hold copyright' == value) {
88
$("div.thesis_license").show();
9+
$("select#thesis_license_id").prop('required', true);
910
} else {
1011
$("div.thesis_license").hide();
1112
$("select#thesis_license_id")[0].value = "";
13+
$("select#thesis_license_id").prop('required', false);
1214
}
1315
};
1416

app/models/thesis.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Thesis < ApplicationRecord
6262

6363
VALIDATION_MSGS = {
6464
copyright: 'Required - Please identify the copyright holder.',
65+
license: 'Required - Please identify the license type.',
6566
graduation_year: 'Required - Please input your year of graduation.',
6667
graduation_month: 'Required - Please select your month of graduation.',
6768
departments: 'Required - Please select your primary department.',

app/views/thesis/edit.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
</div>
127127

128128
<%= f.association :copyright, as: :select,
129+
selected: @thesis.copyright.present? ? @thesis.copyright.id : 2,
129130
required: true,
130131
collection: Copyright.display_to_author,
131132
validate: { present: true },
@@ -142,12 +143,13 @@
142143

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

app/views/thesis/new.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
</div>
125125

126126
<%= f.association :copyright, as: :select,
127+
selected: 2,
127128
required: true,
128129
collection: Copyright.display_to_author,
129130
validate: { presence: true },
@@ -140,12 +141,13 @@
140141

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

0 commit comments

Comments
 (0)