Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Georgetown conditionally required fields #1980

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/assets/javascripts/hyrax/conditionally_required_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This file is used to conditionally require fields on the edit/new work forms.
* At the moment, rights statement is required by default, and rights notes is not.
* One or the other must be filled out in order to create/update a work
*/

// check the value of the rights statement and rights notes fields on page load
$(document).on('turbolinks:load', function () {
$('#generic_work_rights_statement').each(function () {
if (this.value || $('#generic_work_rights_notes')[0].value) return;

$('#generic_work_rights_statement').attr('required', true);
$('#generic_work_rights_notes').attr('required', true);
});
});

// check the value of the rights notes field after its focus is removed
$(document).on('turbolinks:load', function () {
return $('body').on('blur', '#generic_work_rights_notes', function () {
if (this.value === undefined) return;
($('#generic_work_rights_notes').attr('required', true));

if(this.value === '') {
($('#generic_work_rights_statement').attr('required', true))
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
} else {
($('#generic_work_rights_statement').attr('required', false))
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
}
});
});

// check the value of the rights statement field after its focus is removed
$(document).on('turbolinks:load', function () {
return $('body').on('blur', '#generic_work_rights_statement', function () {
if (this.value === undefined || !this.value) return;
($('#generic_work_rights_statement').attr('required', true))
alishaevn marked this conversation as resolved.
Show resolved Hide resolved

if(this.value === '') {
($('#generic_work_rights_notes').attr('required', true))
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
} else {
($('#generic_work_rights_notes').attr('required', false))
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
}
});
});
7 changes: 7 additions & 0 deletions app/views/records/edit_fields/_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if f.object.multiple? key %>
<%= f.input key, as: :multi_value, input_html: { class: 'form-control' }, required: f.object.required?(key) %>
<% elsif key == :rights_notes %>
<%= f.input key, required: f.object.instance_variable_get('@attributes')['rights_statement'].blank? %>
<% else %>
<%= f.input key, required: f.object.required?(key) %>
<% end %>
7 changes: 7 additions & 0 deletions app/views/records/edit_fields/_rights_statement.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% rights_statements = Hyrax.config.rights_statement_service_class.new %>
<%= f.input :rights_statement,
collection: rights_statements.select_active_options,
include_blank: true,
item_helper: rights_statements.method(:include_current_value),
required: false,
input_html: { class: 'form-control' } %>