Skip to content

Commit f6577a8

Browse files
committed
Allow to create sub elements for existing elements, by typing "->"
This fixes issue #666 and #560
1 parent 7fc3153 commit f6577a8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

assets/controllers/elements/structural_entity_select_controller.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {Controller} from "@hotwired/stimulus";
2424

2525
import {trans, ENTITY_SELECT_GROUP_NEW_NOT_ADDED_TO_DB} from '../../translator.js'
2626

27-
2827
export default class extends Controller {
2928
_tomSelect;
3029

@@ -58,7 +57,18 @@ export default class extends Controller {
5857
render: {
5958
item: this.renderItem.bind(this),
6059
option: this.renderOption.bind(this),
61-
option_create: function(data, escape) {
60+
option_create: (data, escape) => {
61+
//If the input starts with "->", we prepend the current selected value, for easier extension of existing values
62+
//This here handles the display part, while the createItem function handles the actual creation
63+
if (data.input.startsWith("->")) {
64+
//Get current selected value
65+
const current = this._tomSelect.getItem(this._tomSelect.getValue()).textContent.replaceAll("→", "->").trim();
66+
//Prepend it to the input
67+
if (current) {
68+
data.input = current + " " + data.input;
69+
}
70+
}
71+
6272
return '<div class="create"><i class="fa-solid fa-plus fa-fw"></i>&nbsp;<strong>' + escape(data.input) + '</strong>&hellip;&nbsp;' +
6373
'<small class="text-muted float-end">(' + addHint +')</small>' +
6474
'</div>';
@@ -76,6 +86,19 @@ export default class extends Controller {
7686
}
7787

7888
createItem(input, callback) {
89+
90+
//If the input starts with "->", we prepend the current selected value, for easier extension of existing values
91+
if (input.startsWith("->")) {
92+
//Get current selected value
93+
let current = this._tomSelect.getItem(this._tomSelect.getValue()).textContent.replaceAll("→", "->").trim();
94+
//Replace no break spaces with normal spaces
95+
current = current.replaceAll("\u00A0", " ");
96+
//Prepend it to the input
97+
if (current) {
98+
input = current + " " + input;
99+
}
100+
}
101+
79102
callback({
80103
//$%$ is a special value prefix, that is used to identify items, that are not yet in the DB
81104
value: '$%$' + input,

assets/tomselect/extend_existing_selection/extend_existing_selection.js

Whitespace-only changes.

0 commit comments

Comments
 (0)