Skip to content

Commit

Permalink
Replace drop-down with objects input with limit of 1 for registered s…
Browse files Browse the repository at this point in the history
…ample attributes
  • Loading branch information
kdp-cloud committed May 24, 2024
1 parent a62a0c7 commit e286ad2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/assets/javascripts/single_page/dynamic_table.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function sanitizeData(data) {

const objectInputTemp = '<input type="hidden" name="_NAME_[]" id="inpt-_NAME_" value="" autocomplete="off" />' +
'<select name="_NAME_[]" id="select-_NAME_" class="form-control _EXTRACLASS_" title="_TITLE_" data-role="seek-objectsinput" ' +
'data-tags-limit="100" _MULTIPLE?_ style="background-color: coral;" data-typeahead-template="_TYPEHEAD_"' +
'data-tags-limit="_LIMIT?_" multiple style="background-color: coral;" data-typeahead-template="_TYPEHEAD_"' +
'data-typeahead-query-url="_URL_" data-allow-new-items=_ALLOW_FREE_TEXT_>_OPTIONS_</select>';

const typeaheadSamplesUrl = "<%= typeahead_samples_path(linked_sample_type_id: '_LINKED_') %>";
Expand Down Expand Up @@ -86,7 +86,8 @@ const handleSelect = (e) => {
}

c["render"] = function(data_, type, full, meta) {
sanitizedData = sanitizeData(data_);
let sanitizedData = sanitizeData(data_);
let data;
if(c.linked_sample_type){
data = sanitizedData && Array.isArray(sanitizedData) ? sanitizedData : [sanitizedData];
data = data[0]?.id ? data : [];
Expand Down Expand Up @@ -592,7 +593,7 @@ function registeredSamplesObjectsInput(column, data, options, url){
}, []);
const hasUnlinkedSamples = unLinkedSamples.length > 0 ? true : false;

const hasMultipleInputs = column.multi_link ? 'multiple="multiple"' : ''
const hasMultipleInputs = column.multi_link ? '100' : '1'
const extraClass = hasUnlinkedSamples ? 'select2__error' : '';
const titleText = hasUnlinkedSamples ? `Sample(s) '${unLinkedSamples.map(uls => uls.title).join(', ')}' not recognised as input. Please correct this issue!` : '';
setTimeout(ObjectsInput.init);
Expand All @@ -604,7 +605,7 @@ function registeredSamplesObjectsInput(column, data, options, url){
.replace('_OPTIONS_', existingOptions)
.replace('_EXTRACLASS_', extraClass)
.replace('_TITLE_', titleText)
.replace('_MULTIPLE?_', hasMultipleInputs)
.replace('_LIMIT?_', hasMultipleInputs)
.replace('_ALLOW_FREE_TEXT_', false);
}
}
Expand All @@ -628,7 +629,7 @@ function cvListObjectsInput(column, data, options, url){
.replace('_OPTIONS_', existingOptions)
.replace('_EXTRACLASS_', extraClass)
.replace('_TITLE_', titleText)
.replace('_MULTIPLE?_', 'multiple="multiple"')
.replace('_LIMIT?_', '')
.replace('_ALLOW_FREE_TEXT_', allowNewItems);
}
}
Expand Down

0 comments on commit e286ad2

Please sign in to comment.