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 all 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
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
//= require bulkrax/application

//= require hyrax
//= require hyrax/conditionally_required_fields
//= require iiif_print

//= require jquery.flot.pie
Expand Down
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);
} else {
$('#generic_work_rights_statement').attr('required', false);
}
});
});

// 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);

if (this.value === '') {
$('#generic_work_rights_notes').attr('required', true);
} else {
$('#generic_work_rights_notes').attr('required', false);
}
});
});
8 changes: 8 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,8 @@
<%# OVERRIDE: Hyrax 3.5.0 so this is not a required field by default %>
<% 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' } %>