@@ -6,32 +6,29 @@ import org.kde.kirigami as Kirigami
66
77ColumnLayout {
88 id: root
9- Layout .preferredWidth : 400
9+ Layout .minimumWidth : 300
1010 property var model: []
11- property var selectedValues: []
12- property string text
11+ property var selectedValues: selectedValues = text !== " " ? text . split ( " , " ) : []
12+ property alias text : field . text
1313 property bool showList: false
14- Component .onCompleted : selectedValues = text .split (" ," )
1514 function update () {
1615 text = selectedValues .join (" ," );
1716 }
1817
1918 RowLayout {
2019 TextField {
2120 id: field
22- text: root .text
2321 Layout .fillWidth : true
2422 color: field .text !== " " ? (isValid ? Kirigami .Theme .textColor : Kirigami .Theme .negativeTextColor ) : Kirigami .Theme .disabledTextColor
2523 property bool isValid: true
2624 onTextChanged: {
2725 checkValid ();
2826 if (isValid) {
29- root .selectedValues = text .split (" ," );
30- root .update ();
27+ root .selectedValues = text !== " " ? text .split (" ," ) : [];
3128 }
3229 }
3330 function checkValid () {
34- isValid = field .text === " " || field .text .split (" ," ).every (item => model .includes (item));
31+ isValid = field .text === " " || field .text .split (" ," ).every (item => root . model .includes (item));
3532 }
3633 Component .onCompleted : {
3734 root .modelChanged .connect (() => {
@@ -76,15 +73,13 @@ ColumnLayout {
7673 Layout .fillWidth : true
7774 text: delegateItem .modelData
7875 onClicked: {
79- if (! root .selectedValues .includes (delegateItem .modelData )) {
80- root .selectedValues .push (delegateItem .modelData );
81- } else {
82- root .selectedValues = root .selectedValues .filter (p => p !== delegateItem .modelData );
83- }
84- root .update ();
76+ delegateItem .updateSelected ();
8577 }
8678 }
8779 onClicked: {
80+ delegateItem .updateSelected ();
81+ }
82+ function updateSelected () {
8883 if (! root .selectedValues .includes (delegateItem .modelData )) {
8984 root .selectedValues .push (delegateItem .modelData );
9085 } else {
0 commit comments