Skip to content

Commit 5b505c5

Browse files
committed
TD-3308: Keyword field only allows 50 chars which is problematic when adding multiple keywords at once
1 parent 4ade7e6 commit 5b505c5

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/Edit.cshtml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165

166166
</div>
167167
<div class="col-12">
168-
<p class="hint">You can enter a maximum of 50 characters</p>
168+
<p class="hint">You can enter a maximum of 50 characters per keyword.</p>
169169
<div class="keyword-list">
170170
@{
171171
var i = 0;
@@ -334,29 +334,31 @@
334334
});
335335
336336
$('#add-keyword').on('click', function () {
337-
var $keywordInput = $('#add-keyword-input');
338-
var value = $keywordInput.val();
339-
if (!value) {
340-
return;
341-
}
342-
value = value.trim();
343-
if (keywords.indexOf(value) === -1) {
344-
keywords.push(value);
345-
$('#Keywords').val(keywords);
346-
var tag = $('<div class="keyword-tag"><p>' + value + '</p><i class="fa fa-times"></i><input class="keyword-value" type="hidden" value="' + value + '" /></div>');
347-
tag.find('.fa-times').on('click', removeKeyword);
348-
$('.keyword-list').append(tag);
349-
$keywordInput.val("");
350-
// reindex the keyword inputs
351-
$('.keyword-value').each(function (i, x) {
352-
$(x).attr('name', "Keywords[" + i + "]");
353-
});
354-
}
355-
if (keywords.length > 4) {
356-
$('#add-keyword').attr('disabled', 'disabled');
357-
$('#add-keyword-input').attr('disabled', 'disabled');
337+
var $keywordInput = $('#add-keyword-input');
338+
var value = $keywordInput.val();
339+
if (!value) {
340+
return;
341+
}
342+
343+
// Split the input value by commas and trim each keyword
344+
var values = value.split(',').map(function (item) {
345+
return item.trim();
346+
});
347+
348+
values.forEach(function (value) {
349+
if (value && keywords.indexOf(value) === -1) {
350+
keywords.push(value);
351+
$('#Keywords').val(keywords);
352+
var tag = $('<div class="keyword-tag"><p>' + value + '</p><i class="fa fa-times"></i><input class="keyword-value" type="hidden" value="' + value + '" /></div>');
353+
tag.find('.fa-times').on('click', removeKeyword);
354+
$('.keyword-list').append(tag);
355+
356+
// reindex the keyword inputs
357+
$('.keyword-value').each(function (i, x) {
358+
$(x).attr('name', "Keywords[" + i + "]");
359+
});
358360
}
359-
});
361+
});
360362
361363
// url
362364
var oldUrl = "";

LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/ContentCommon.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
To help learners find this resource, type one or more relevant keywords separated by commas and click 'Add'.
9191
</div>
9292
<div class="col-12 mt-4 input-with-button">
93-
<input id="newKeyword" aria-labelledby="keyword-label" type="text" class="form-control" maxlength="50" v-model="newKeyword" v-bind:class="{ 'input-validation-error': keywordError }" @input="keywordError=false" @change="keywordChange" />
93+
<input id="newKeyword" aria-labelledby="keyword-label" type="text" class="form-control" maxlength="260" v-model="newKeyword" v-bind:class="{ 'input-validation-error': keywordError }" @input="keywordError=false" @change="keywordChange" />
9494
<button type="button" class="nhsuk-button nhsuk-button--secondary ml-3 nhsuk-u-margin-bottom-0" @click="addKeyword">&nbsp;Add</button>
9595
</div>
9696
<div class="col-12 footer-text">
97-
You can enter a maximum of 50 characters
97+
You can enter a maximum of 50 characters per keyword
9898
</div>
9999
</div>
100100
</div>
@@ -529,7 +529,7 @@
529529
if (!this.keywords.find(_keyword => allTrimmedKeyword.includes(_keyword.keyword.toLowerCase()))) {
530530
for (var i = 0; i < allTrimmedKeyword.length; i++) {
531531
let item = allTrimmedKeyword[i];
532-
if (item.length > 0) {
532+
if (item.length > 0 && item.length <= 50) {
533533
let newkeywordObj = new KeywordModel();
534534
newkeywordObj.keyword = item;
535535
newkeywordObj.resourceVersionId = this.resourceDetail.resourceVersionId;

0 commit comments

Comments
 (0)