]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - form/KVComboBox.js
use eslint and execute as check target
[proxmox-widget-toolkit.git] / form / KVComboBox.js
CommitLineData
211267b8
DM
1/* Key-Value ComboBox
2 *
3 * config properties:
4 * comboItems: an array of Key - Value pairs
5 * deleteEmpty: if set to true (default), an empty value received from the
6 * comboBox will reset the property to its default value
7 */
a4eeb593 8Ext.define('Proxmox.form.KVComboBox', {
211267b8
DM
9 extend: 'Ext.form.field.ComboBox',
10 alias: 'widget.proxmoxKVComboBox',
11
f0372135 12 config: {
01031528 13 deleteEmpty: true,
f0372135
DM
14 },
15
211267b8
DM
16 comboItems: undefined,
17 displayField: 'value',
18 valueField: 'key',
19 queryMode: 'local',
20
21 // overide framework function to implement deleteEmpty behaviour
22 getSubmitData: function() {
05a977a2 23 let me = this,
211267b8
DM
24 data = null,
25 val;
26 if (!me.disabled && me.submitValue) {
27 val = me.getSubmitValue();
28 if (val !== null && val !== '' && val !== '__default__') {
29 data = {};
30 data[me.getName()] = val;
f0372135 31 } else if (me.getDeleteEmpty()) {
211267b8 32 data = {};
01031528 33 data.delete = me.getName();
211267b8
DM
34 }
35 }
36 return data;
37 },
38
39 validator: function(val) {
05a977a2 40 let me = this;
211267b8
DM
41
42 if (me.editable || val === null || val === '') {
43 return true;
44 }
45
46 if (me.store.getCount() > 0) {
05a977a2
TL
47 let values = me.multiSelect ? val.split(me.delimiter) : [val];
48 let items = me.store.getData().collect('value', 'data');
211267b8
DM
49 if (Ext.Array.every(values, function(value) {
50 return Ext.Array.contains(items, value);
51 })) {
52 return true;
53 }
54 }
55
56 // returns a boolean or string
211267b8
DM
57 return "value '" + val + "' not allowed!";
58 },
59
60 initComponent: function() {
05a977a2 61 let me = this;
211267b8
DM
62
63 me.store = Ext.create('Ext.data.ArrayStore', {
64 model: 'KeyValue',
01031528 65 data: me.comboItems,
211267b8
DM
66 });
67
68 if (me.initialConfig.editable === undefined) {
69 me.editable = false;
70 }
71
72 me.callParent();
c8b66b2b
OB
73 },
74
75 setComboItems: function(items) {
05a977a2 76 let me = this;
c8b66b2b
OB
77
78 me.getStore().setData(items);
01031528 79 },
c8b66b2b 80
211267b8 81});