Comma Seperated Tags List Walker Feature

Commit adds support of adding a list with commas to the tag field.
This commit is contained in:
Sebastian 2023-02-28 21:11:49 +01:00 committed by GitHub
parent e8cfad9241
commit b0013d5d2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -807,18 +807,31 @@
?> ?>
</select> </select>
<script> <script>
let addToTagList = function (value) {
// trim
value = value.replace(/^\s+|\s+$/g,"");
if ($("#tags option[value='" + value + "']").length > 0) {
$("#tags option[value='" + value + "']").prop('selected', true);
} else {
$('#tags').prepend($('<option>', {
value: value,
text: value,
selected: true
}));
}
};
$(document).ready(function() { $(document).ready(function() {
$('#addTag').keypress(function(e) { $('#addTag').keypress(function(e) {
if (e.which == 13) { if (e.which == 13) {
var value = $(this).val(); var value = $(this).val();
if ($("#tags option[value='" + value + "']").length > 0) { // Split input?
$("#tags option[value='" + value + "']").prop('selected', true); if (value.indexOf(',') > -1) {
value.split(',').forEach( function(s) {
addToTagList(s);
});
} else { } else {
$('#tags').prepend($('<option>', { addToTagList(value);
value: $(this).val(),
text: $(this).val(),
selected: true
}));
} }
$(this).val(''); $(this).val('');
return false; return false;