-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComboEmptyChoice.js
More file actions
52 lines (46 loc) · 1.5 KB
/
Copy pathComboEmptyChoice.js
File metadata and controls
52 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* The author disclaims copyright to this source code. In place of
* a legal notice, here is a blessing:
*
* May you do good and not evil.
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
*/
Ext.define('Ext.ux.plugin.ComboEmptyChoice', {
extend: 'Ext.AbstractPlugin',
init: function(combo){
var me = this;
combo.clearOption = combo.clearOption || '<i>Clear</i>';
combo.setValue = this._setValue;
if(combo.getStore()){
combo.getStore().on('load', function(s, r, ok, op, eop){
me.storeLoad(s, r, ok, op, eop, combo);
});
}
},
/*
* Creates a dummy instance of the store's model to act as the blank option.
*/
storeLoad: function(s, r, ok, op, eop, combo){
var config = {};
config[combo.displayField] = combo.clearOption;
config[combo.valueField] = -1;
var model = Ext.create(s.model, config);
s.add(model);
},
/*
* If the choosen option was the blank one, clears the combobox.
*/
_setValue: function(value){
if(!value){
return;
}
if(!(value instanceof Array)){
value = [value];
}
if(value[0].data[this.valueField] == -1){
return Ext.form.field.ComboBox.prototype.setValue.apply(this, []);
}
return Ext.form.field.ComboBox.prototype.setValue.apply(this, value);
}
});