]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - form/KVComboBox.js
PasswordEdit.js: use larger labels to avoid line break
[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 */
8Ext.define('proxmox.form.KVComboBox', {
9 extend: 'Ext.form.field.ComboBox',
10 alias: 'widget.proxmoxKVComboBox',
11
12 deleteEmpty: true,
13 comboItems: undefined,
14 displayField: 'value',
15 valueField: 'key',
16 queryMode: 'local',
17
18 // overide framework function to implement deleteEmpty behaviour
19 getSubmitData: function() {
20 var me = this,
21 data = null,
22 val;
23 if (!me.disabled && me.submitValue) {
24 val = me.getSubmitValue();
25 if (val !== null && val !== '' && val !== '__default__') {
26 data = {};
27 data[me.getName()] = val;
28 } else if (me.deleteEmpty) {
29 data = {};
30 data['delete'] = me.getName();
31 }
32 }
33 return data;
34 },
35
36 validator: function(val) {
37 var me = this;
38
39 if (me.editable || val === null || val === '') {
40 return true;
41 }
42
43 if (me.store.getCount() > 0) {
44 var values = me.multiSelect ? val.split(me.delimiter) : [val];
45 var items = me.store.getData().collect('value', 'data');
46 if (Ext.Array.every(values, function(value) {
47 return Ext.Array.contains(items, value);
48 })) {
49 return true;
50 }
51 }
52
53 // returns a boolean or string
54 /*jslint confusion: true */
55 return "value '" + val + "' not allowed!";
56 },
57
58 initComponent: function() {
59 var me = this;
60
61 me.store = Ext.create('Ext.data.ArrayStore', {
62 model: 'KeyValue',
63 data : me.comboItems
64 });
65
66 if (me.initialConfig.editable === undefined) {
67 me.editable = false;
68 }
69
70 me.callParent();
71 }
72});