@@ -24,7 +24,6 @@ import {Controller} from "@hotwired/stimulus";
24
24
25
25
import { trans , ENTITY_SELECT_GROUP_NEW_NOT_ADDED_TO_DB } from '../../translator.js'
26
26
27
-
28
27
export default class extends Controller {
29
28
_tomSelect ;
30
29
@@ -58,7 +57,18 @@ export default class extends Controller {
58
57
render : {
59
58
item : this . renderItem . bind ( this ) ,
60
59
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
+
62
72
return '<div class="create"><i class="fa-solid fa-plus fa-fw"></i> <strong>' + escape ( data . input ) + '</strong>… ' +
63
73
'<small class="text-muted float-end">(' + addHint + ')</small>' +
64
74
'</div>' ;
@@ -76,6 +86,19 @@ export default class extends Controller {
76
86
}
77
87
78
88
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
+
79
102
callback ( {
80
103
//$%$ is a special value prefix, that is used to identify items, that are not yet in the DB
81
104
value : '$%$' + input ,
0 commit comments