From 609f48cb199cb6d8a19ddc38c641f3e218cb1f68 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Tue, 28 Apr 2020 23:25:32 -0700 Subject: [PATCH 1/4] move more logic in to data attributes, reduce how much js is trying to accomplish to improve performance --- .../hyrax/save_work/required_fields.es6 | 116 ++++++++---------- hyrax/app/inputs/nested_affiliation_input.rb | 5 +- hyrax/app/inputs/nested_attributes_input.rb | 18 ++- .../nested_chemical_composition_input.rb | 5 +- ...nested_crystallographic_structure_input.rb | 5 +- .../inputs/nested_custom_property_input.rb | 11 +- hyrax/app/inputs/nested_date_input.rb | 7 +- hyrax/app/inputs/nested_event_input.rb | 25 ++-- hyrax/app/inputs/nested_identifier_input.rb | 7 +- .../nested_instrument_function_input.rb | 20 +-- hyrax/app/inputs/nested_instrument_input.rb | 21 ++-- .../app/inputs/nested_material_type_input.rb | 15 ++- hyrax/app/inputs/nested_organization_input.rb | 15 ++- hyrax/app/inputs/nested_person_input.rb | 10 +- .../inputs/nested_purchase_record_input.rb | 15 ++- hyrax/app/inputs/nested_relation_input.rb | 20 +-- hyrax/app/inputs/nested_rights_input.rb | 13 +- hyrax/app/inputs/nested_shape_input.rb | 5 +- hyrax/app/inputs/nested_source_input.rb | 42 ++++--- .../app/inputs/nested_specimen_type_input.rb | 10 +- .../inputs/nested_state_of_matter_input.rb | 5 +- .../inputs/nested_structural_feature_input.rb | 15 ++- hyrax/app/inputs/nested_version_input.rb | 10 +- 23 files changed, 238 insertions(+), 177 deletions(-) diff --git a/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 b/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 index 556eee7e..58441d02 100644 --- a/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 +++ b/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 @@ -1,3 +1,7 @@ +jQuery.fn.hasVal = function() { + return this !== null && this.val().length > 0; +} + export class RequiredFields { // Monitors the form and runs the callback if any of the required fields change constructor(form, callback) { @@ -7,80 +11,68 @@ export class RequiredFields { } get areComplete() { - this.reload() - return this.requiredFields.filter((n, elem) => { return this.isValuePresent(elem) } ).length === 0 + var missing = this.requiredFields.filter((n, elem) => { return !this.isNeededValuePresent(elem) } ) + return missing.length === 0 } - requiredIf() { - // this is hard-coded - to do, use erb to grab a list - let conditions = ['any', 'name'] - var elems = [] - - // build the list of elem; cleanup - $.each(conditions, function(n,value) { - $(":input.require-if-"+value).each(function(n,elem) { - // Remove the required class, attribute and box-shadow (they will be reset if needed) - $(elem).removeClass('required'); - $(elem).attr('required', null); - $(elem).removeAttr('style'); - elems.push({ value : elem }) - }); - }); + // helper to clear the 'required' styling + notRequired(elem, label) { + $(label).removeClass('required') + $(label).find('span').remove() - $.each(elems, function(n,elem_obj) { - var required = elem_obj.value - var id = $(required).attr('id'); - var parents = $(required).closest('div.multi-nested') + $(elem).removeClass('required'); + $(elem).attr('required', null); + $(elem).removeAttr('style'); + } - if (elem_obj.key === 'any') { - var label = $(parents).find('label[for="' + id + '_"]') - } else { - var label = $(parents).find('label[for="' + id + '_' + elem_obj.key + '"]') - } + required(elem, label) { + $(label).addClass('required control-label') + $(label).append('required') + $(elem).addClass('required'); + $(elem).attr('required', 'required'); + $(elem).css('box-shadow','0px 0px 0px 2px red'); + } - // Remove the required class and span (they will be reset if needed) - $(label).removeClass('required') - $(label).find('span').remove(); - - // Find the immediate field-wrapper - // Gather the inputs - this.inputs = $(required).closest('li.field-wrapper').find(':input'); - // Skip the current elem, any hidden fields and any buttons, skip operator (role), Processed (date) (pre-filled but should not be required) - if (this.inputs.filter((n, el) => { - if ( - !el.parentNode.className.includes("hidden") && !el.className.includes('btn') && !el.className.includes('remove-hidden') && el != required && el.value !== 'operator' && el.value !== 'Processed' ) { - return (el.value !== ''); - } - } ).length > 0) { - // Add the required classes, attributes and labels - if ( $(label).has('span').length === 0 ) { - $(label).addClass('required control-label') - $(label).append('required'); - $(required).addClass('required'); - $(required).attr('required', 'required'); - // Only add the css if the value is empty - if ( ($(required).val() === null) || ($(required).val().length < 1) ) { - $(required).css('box-shadow','0px 0px 0px 2px red'); - } - } - }; - }); + isNeededValuePresent(elem) { + // if the value is filled in, do not check further + if($(elem).hasVal()) return true - // Find all inputs in multi-nested blocks (where conditional requirements will be in place) - this.conditionalRequiredFields = this.form.find('div.multi-nested :input') - this.conditionalRequiredFields.change(this.callback) - } + var present = true + if($(elem).data('required')){ + var requirements = $(elem).data('required').split(';') + + // Special "any" case + if(requirements.includes('any')){ + $(elem).parents('.form-group').find(':input').not('[type=hidden], [data-skip=true]').each(function(i) { + if($(this).hasVal()) return (present = false) + }) + } else { + // Go through each requirement + $.each(requirements, function(i, e) { + if($(`input[data-name=${e}]`).hasVal()) return (present = false) + }) + } - isValuePresent(elem) { - return ($(elem).val() === null) || ($(elem).val().length < 1) + // TODO this label replace is not right, but ids with [] are not allowed in htlm + // and need to be fixed in the nested inputs. Jquery throws an exeption if we try + // to match on for block with square brackets + var label = $(`label[for=${elem.id.replace(/\[|\]/g, '_')}]`) + // only run css updates if they are needed, as they are expensive + if(present && label.hasClass('required')) { + this.notRequired(elem, label) + } else if( !present && !label.hasClass('required')) { + this.required(elem, label) + } + return present + } else { + return false + } } // Reassign requiredFields because fields may have been added or removed. reload() { - // Add any new required flags - this.requiredIf() // ":input" matches all input, select or textarea fields. - this.requiredFields = this.form.find(':input[required]') + this.requiredFields = this.form.find(':input[required], :input.required-if') this.requiredFields.change(this.callback) } } diff --git a/hyrax/app/inputs/nested_affiliation_input.rb b/hyrax/app/inputs/nested_affiliation_input.rb index 3db82d66..3edff870 100644 --- a/hyrax/app/inputs/nested_affiliation_input.rb +++ b/hyrax/app/inputs/nested_affiliation_input.rb @@ -24,14 +24,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '' diff --git a/hyrax/app/inputs/nested_attributes_input.rb b/hyrax/app/inputs/nested_attributes_input.rb index f431ec4c..0804e5d9 100644 --- a/hyrax/app/inputs/nested_attributes_input.rb +++ b/hyrax/app/inputs/nested_attributes_input.rb @@ -118,15 +118,21 @@ def id_for(attribute_name, index, field, parent=@builder.object_name) end def class_for(attribute_name, field, model_class=@builder.object.class.model_class) + requirements = model_class.requirements_for(attribute_name) + if (requirements[:required] && requirements[:required].flatten.include?(field.to_s)) || + (requirements[:conditional] && requirements[:conditional][field].present?) + 'required-if' + else + '' + end + end + + def requirements_for(attribute_name, field, model_class=@builder.object.class.model_class) requirements = model_class.requirements_for(attribute_name) if requirements[:required] && requirements[:required].flatten.include?(field.to_s) - 'require-if-any' + 'any' elsif requirements[:conditional] && requirements[:conditional][field].present? - cl = [] - requirements[:conditional][field].each do | conditional_field | - cl << "require-if-#{conditional_field}" - end - cl.join(' ') + requirements[:conditional][field].join(';') end end end diff --git a/hyrax/app/inputs/nested_chemical_composition_input.rb b/hyrax/app/inputs/nested_chemical_composition_input.rb index decf7d67..5c4e7102 100644 --- a/hyrax/app/inputs/nested_chemical_composition_input.rb +++ b/hyrax/app/inputs/nested_chemical_composition_input.rb @@ -45,14 +45,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_crystallographic_structure_input.rb b/hyrax/app/inputs/nested_crystallographic_structure_input.rb index c460a150..18a0653c 100644 --- a/hyrax/app/inputs/nested_crystallographic_structure_input.rb +++ b/hyrax/app/inputs/nested_crystallographic_structure_input.rb @@ -45,14 +45,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_custom_property_input.rb b/hyrax/app/inputs/nested_custom_property_input.rb index 0d0752f5..0db594df 100644 --- a/hyrax/app/inputs/nested_custom_property_input.rb +++ b/hyrax/app/inputs/nested_custom_property_input.rb @@ -21,15 +21,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -42,14 +44,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_date_input.rb b/hyrax/app/inputs/nested_date_input.rb index 00f176a7..a15c7653 100644 --- a/hyrax/app/inputs/nested_date_input.rb +++ b/hyrax/app/inputs/nested_date_input.rb @@ -24,10 +24,12 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + date_options = DateService.new.select_all_options out << "
" out << template.select_tag(field_name, template.options_for_select(date_options, field_value), - label: '', class: 'select form-control', prompt: 'choose type', id: field_id) + label: '', class: 'select form-control', prompt: 'choose type', id: field_id, data: {required: field_requirements, name: field, skip: true}) out << '
' # --- date @@ -36,11 +38,12 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - data: { provide: 'datepicker' }, required: required, class: field_class)) + data: { provide: 'datepicker', required: field_requirements, name: field }, required: required, class: field_class)) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_event_input.rb b/hyrax/app/inputs/nested_event_input.rb index baae3780..e0cacd17 100644 --- a/hyrax/app/inputs/nested_event_input.rb +++ b/hyrax/app/inputs/nested_event_input.rb @@ -17,15 +17,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -34,15 +35,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_name = name_for(attribute_name, index, field, parent) field_id = id_for(attribute_name, index, field, parent) field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -52,16 +54,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - data: { provide: 'datepicker' }, required: false, class: field_class)) + data: { provide: 'datepicker', required: field_requirements, name: field }, required: false, class: field_class)) out << '
' out << '
' # row @@ -71,16 +74,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - data: { provide: 'datepicker' }, required: false, class: field_class)) + data: { provide: 'datepicker', required: field_requirements, name: field }, required: false, class: field_class)) out << '
' out << '
' # row @@ -93,14 +97,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_identifier_input.rb b/hyrax/app/inputs/nested_identifier_input.rb index 33a0b93e..af636032 100644 --- a/hyrax/app/inputs/nested_identifier_input.rb +++ b/hyrax/app/inputs/nested_identifier_input.rb @@ -24,12 +24,14 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + id_options = IdentifierService.new.select_all_options out << "
" out << template.select_tag(field_name, template.options_for_select(id_options, field_value), - label: '', class: 'select form-control', prompt: 'choose type', id: field_id) + label: '', class: 'select form-control ' + field_class, prompt: 'choose type', id: field_id, data: {required: field_requirements, name: field}) out << '
' # --- identifier @@ -38,11 +40,12 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - required: required, class: field_class)) + required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_instrument_function_input.rb b/hyrax/app/inputs/nested_instrument_function_input.rb index 7c239a49..737d5e0f 100644 --- a/hyrax/app/inputs/nested_instrument_function_input.rb +++ b/hyrax/app/inputs/nested_instrument_function_input.rb @@ -21,15 +21,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -39,15 +40,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -57,15 +59,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -78,14 +81,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_instrument_input.rb b/hyrax/app/inputs/nested_instrument_input.rb index da13db66..7bd4bbb4 100644 --- a/hyrax/app/inputs/nested_instrument_input.rb +++ b/hyrax/app/inputs/nested_instrument_input.rb @@ -23,15 +23,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -41,15 +42,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -79,15 +82,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -155,15 +159,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row diff --git a/hyrax/app/inputs/nested_material_type_input.rb b/hyrax/app/inputs/nested_material_type_input.rb index e8413e74..a0b21042 100644 --- a/hyrax/app/inputs/nested_material_type_input.rb +++ b/hyrax/app/inputs/nested_material_type_input.rb @@ -23,15 +23,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -41,15 +42,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -59,15 +61,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row diff --git a/hyrax/app/inputs/nested_organization_input.rb b/hyrax/app/inputs/nested_organization_input.rb index e00d4420..7927afe3 100644 --- a/hyrax/app/inputs/nested_organization_input.rb +++ b/hyrax/app/inputs/nested_organization_input.rb @@ -21,15 +21,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -39,15 +40,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -61,14 +63,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << " ' out << " ' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_person_input.rb b/hyrax/app/inputs/nested_person_input.rb index d3d304af..9df85f76 100644 --- a/hyrax/app/inputs/nested_person_input.rb +++ b/hyrax/app/inputs/nested_person_input.rb @@ -23,15 +23,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field} )) out << '
' out << '
' # row @@ -42,15 +43,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << template.select_tag(field_name, template.options_for_select(role_options, field_value), - prompt: 'Select role played', label: '', class: 'select form-control', id: field_id, required: required, class: field_class) + prompt: 'Select role played', label: '', class: 'select form-control', id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field, skip: true}) out << '
' out << '
' # row diff --git a/hyrax/app/inputs/nested_purchase_record_input.rb b/hyrax/app/inputs/nested_purchase_record_input.rb index 69ab538a..86afebf8 100644 --- a/hyrax/app/inputs/nested_purchase_record_input.rb +++ b/hyrax/app/inputs/nested_purchase_record_input.rb @@ -23,15 +23,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -41,16 +42,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - data: { provide: 'datepicker' }, required: required, class: field_class)) + data: { provide: 'datepicker', required: field_requirements, name: field }, required: required, class: field_class)) out << '
' out << '
' # row @@ -119,15 +121,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row diff --git a/hyrax/app/inputs/nested_relation_input.rb b/hyrax/app/inputs/nested_relation_input.rb index e8320340..1c0e3a78 100644 --- a/hyrax/app/inputs/nested_relation_input.rb +++ b/hyrax/app/inputs/nested_relation_input.rb @@ -17,15 +17,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, 'Title', required: required) + out << template.label_tag(field_id, 'Title', required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -35,15 +36,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -56,7 +58,7 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje # out << "
" # out << "
" - # out << template.label_tag(field_name, field.to_s.humanize, required: false) + # out << template.label_tag(field_id, field.to_s.humanize, required: false) # out << '
' # out << "
" @@ -74,17 +76,19 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + role_options = RelationshipService.new.select_all_options out << "
" - out << template.label_tag(field_name, 'Relationship', required: required) + out << template.label_tag(field_id, 'Relationship', required: required) out << '
' out << "
" out << template.select_tag(field_name, template.options_for_select(role_options, field_value), - label: '', class: 'select form-control', prompt: 'choose relationship', - id: field_id, required: required) + label: '', class: 'select form-control' + field_class, prompt: 'choose relationship', + id: field_id, required: required, data: {required: field_requirements, name: field}) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_rights_input.rb b/hyrax/app/inputs/nested_rights_input.rb index cf7544db..dc41091f 100644 --- a/hyrax/app/inputs/nested_rights_input.rb +++ b/hyrax/app/inputs/nested_rights_input.rb @@ -17,18 +17,21 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + active_options = Hyrax::LicenseService.new.select_active_options out << "
" out << "
" - out << template.label_tag(field_name, 'Rights', required: required) + out << template.label_tag(field_id, 'Rights', required: required) out << '
' out << "
" out << template.select_tag(field_name, template.options_for_select(active_options, field_value), prompt: 'Select license', label: '', class: 'select form-control', - id: field_id, required: required, class: field_class) + id: field_id, required: required, class: field_class, + data: {required: field_requirements, name: field}) out << '
' out << '
' # row @@ -41,15 +44,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) + out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - data: { provide: 'datepicker' }, required: false, class: field_class)) + data: {required: field_requirements, name: field, provide: 'datepicker' }, required: false, class: field_class)) out << '
' # delete checkbox diff --git a/hyrax/app/inputs/nested_shape_input.rb b/hyrax/app/inputs/nested_shape_input.rb index f02e7529..6a8ea6f6 100644 --- a/hyrax/app/inputs/nested_shape_input.rb +++ b/hyrax/app/inputs/nested_shape_input.rb @@ -45,14 +45,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_source_input.rb b/hyrax/app/inputs/nested_source_input.rb index b83b219c..91a8257c 100644 --- a/hyrax/app/inputs/nested_source_input.rb +++ b/hyrax/app/inputs/nested_source_input.rb @@ -17,15 +17,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -35,15 +36,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -53,15 +55,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -71,15 +74,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -89,15 +93,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -107,15 +112,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -125,15 +131,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) - + field_requirements = requirements_for(attribute_name, field) + out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -146,14 +153,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: false) + out << template.label_tag(field_id, field.to_s.humanize, required: false) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_specimen_type_input.rb b/hyrax/app/inputs/nested_specimen_type_input.rb index 8a0d9e55..b07c1c02 100644 --- a/hyrax/app/inputs/nested_specimen_type_input.rb +++ b/hyrax/app/inputs/nested_specimen_type_input.rb @@ -23,15 +23,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -79,15 +80,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row diff --git a/hyrax/app/inputs/nested_state_of_matter_input.rb b/hyrax/app/inputs/nested_state_of_matter_input.rb index 19a371ea..59c07927 100644 --- a/hyrax/app/inputs/nested_state_of_matter_input.rb +++ b/hyrax/app/inputs/nested_state_of_matter_input.rb @@ -45,14 +45,15 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: false, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox diff --git a/hyrax/app/inputs/nested_structural_feature_input.rb b/hyrax/app/inputs/nested_structural_feature_input.rb index 10a5c99a..d8f22242 100644 --- a/hyrax/app/inputs/nested_structural_feature_input.rb +++ b/hyrax/app/inputs/nested_structural_feature_input.rb @@ -23,15 +23,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -41,15 +42,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -59,15 +61,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row diff --git a/hyrax/app/inputs/nested_version_input.rb b/hyrax/app/inputs/nested_version_input.rb index f7e2a726..2de8b242 100644 --- a/hyrax/app/inputs/nested_version_input.rb +++ b/hyrax/app/inputs/nested_version_input.rb @@ -17,15 +17,16 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, - options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class)) + options.merge(value: field_value, name: field_name, id: field_id, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' out << '
' # row @@ -35,16 +36,17 @@ def build_components(attribute_name, value, index, options, parent=@builder.obje field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first field_class = class_for(attribute_name, field) + field_requirements = requirements_for(attribute_name, field) out << "
" out << "
" - out << template.label_tag(field_name, field.to_s.humanize, required: required) + out << template.label_tag(field_id, field.to_s.humanize, required: required) out << '
' out << "
" out << @builder.text_field(field_name, options.merge(value: field_value, name: field_name, id: field_id, - data: { provide: 'datepicker' }, required: required, class: field_class)) + data: { provide: 'datepicker' }, required: required, class: field_class, data: {required: field_requirements, name: field})) out << '
' # --- delete checkbox From 395e70fbc0ceab70b73e10ae790cbbc2587e0636 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Tue, 28 Apr 2020 23:33:01 -0700 Subject: [PATCH 2/4] more clear boolean logic --- .../hyrax/save_work/required_fields.es6 | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 b/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 index 58441d02..d030f218 100644 --- a/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 +++ b/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 @@ -11,7 +11,7 @@ export class RequiredFields { } get areComplete() { - var missing = this.requiredFields.filter((n, elem) => { return !this.isNeededValuePresent(elem) } ) + var missing = this.requiredFields.filter((n, elem) => { return this.isRequiredButBlank(elem) } ) return missing.length === 0 } @@ -33,23 +33,23 @@ export class RequiredFields { $(elem).css('box-shadow','0px 0px 0px 2px red'); } - isNeededValuePresent(elem) { + isRequiredButBlank(elem) { // if the value is filled in, do not check further - if($(elem).hasVal()) return true + if($(elem).hasVal()) return false - var present = true + var requiredButBlank = false if($(elem).data('required')){ var requirements = $(elem).data('required').split(';') // Special "any" case if(requirements.includes('any')){ $(elem).parents('.form-group').find(':input').not('[type=hidden], [data-skip=true]').each(function(i) { - if($(this).hasVal()) return (present = false) + if($(this).hasVal()) return (requiredButBlank = true) }) } else { // Go through each requirement $.each(requirements, function(i, e) { - if($(`input[data-name=${e}]`).hasVal()) return (present = false) + if($(`input[data-name=${e}]`).hasVal()) return (requiredButBlank = true) }) } @@ -58,14 +58,14 @@ export class RequiredFields { // to match on for block with square brackets var label = $(`label[for=${elem.id.replace(/\[|\]/g, '_')}]`) // only run css updates if they are needed, as they are expensive - if(present && label.hasClass('required')) { + if(!requiredButBlank && label.hasClass('required')) { this.notRequired(elem, label) - } else if( !present && !label.hasClass('required')) { + } else if( requiredButBlank && !label.hasClass('required')) { this.required(elem, label) } - return present + return requiredButBlank } else { - return false + return true } } From 109ef2b0c61eef7856ad7fd947bc93f8073717ab Mon Sep 17 00:00:00 2001 From: Julie Allinson Date: Fri, 8 May 2020 10:06:22 +0100 Subject: [PATCH 3/4] extend required_fields to add complex_rights and description (as per RJ list) small change to js extended requirements --- .../assets/javascripts/hyrax/save_work/required_fields.es6 | 6 +++++- hyrax/app/forms/hyrax/dataset_form.rb | 5 +++-- hyrax/config/nims_metadata_requirements.yml | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 b/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 index d030f218..5b815b33 100644 --- a/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 +++ b/hyrax/app/assets/javascripts/hyrax/save_work/required_fields.es6 @@ -56,8 +56,12 @@ export class RequiredFields { // TODO this label replace is not right, but ids with [] are not allowed in htlm // and need to be fixed in the nested inputs. Jquery throws an exeption if we try // to match on for block with square brackets - var label = $(`label[for=${elem.id.replace(/\[|\]/g, '_')}]`) + var elem_id = elem.id.replace(/\[|\]/g, '_') + var label = $(`label[for=${elem_id.replace(/__/g, '_')}]`) + // var label = $(`label[for=${elem.id.replace(/\[|\]/g, '_')}]`) + // only run css updates if they are needed, as they are expensive + // this first one never gets called if(!requiredButBlank && label.hasClass('required')) { this.notRequired(elem, label) } else if( requiredButBlank && !label.hasClass('required')) { diff --git a/hyrax/app/forms/hyrax/dataset_form.rb b/hyrax/app/forms/hyrax/dataset_form.rb index 3e16bf08..e37ff83a 100644 --- a/hyrax/app/forms/hyrax/dataset_form.rb +++ b/hyrax/app/forms/hyrax/dataset_form.rb @@ -36,8 +36,9 @@ class DatasetForm < Hyrax::Forms::WorkForm :title] self.required_fields += [ - # # Adding all required fields in order of display in form - :supervisor_approval, :title, :data_origin + # Adding all required fields in order of display in form + :supervisor_approval, :title, :data_origin, + :description, :complex_rights ] def metadata_tab_terms diff --git a/hyrax/config/nims_metadata_requirements.yml b/hyrax/config/nims_metadata_requirements.yml index 63385074..6c562757 100644 --- a/hyrax/config/nims_metadata_requirements.yml +++ b/hyrax/config/nims_metadata_requirements.yml @@ -29,6 +29,7 @@ nims: complex_identifier: required: - ['identifier'] + - ['scheme'] complex_rights: required: - ['rights'] From aff9b3001673d1c8e7a4a6fff09919789f3a90b9 Mon Sep 17 00:00:00 2001 From: Julie Allinson Date: Fri, 8 May 2020 10:42:28 +0100 Subject: [PATCH 4/4] back out required_fields changes - there is another branch coming for that --- hyrax/app/forms/hyrax/dataset_form.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hyrax/app/forms/hyrax/dataset_form.rb b/hyrax/app/forms/hyrax/dataset_form.rb index e37ff83a..06452d7d 100644 --- a/hyrax/app/forms/hyrax/dataset_form.rb +++ b/hyrax/app/forms/hyrax/dataset_form.rb @@ -37,8 +37,7 @@ class DatasetForm < Hyrax::Forms::WorkForm self.required_fields += [ # Adding all required fields in order of display in form - :supervisor_approval, :title, :data_origin, - :description, :complex_rights + :supervisor_approval, :title, :data_origin ] def metadata_tab_terms