1 //<script type="text/javascript">
4 * A facebook style adder... for lists of email / people etc...
11 Ext.form.ComboBoxLister = function(config){
13 Ext.form.ComboBoxLister.superclass.constructor.call(this, config);
14 this.items = new Roo.util.MixedCollection(false);
15 this.on('select', function(cb, rec, ix) {
16 this.addItem(rec.data);
18 this.el.dom.value = '';
19 //cb.lastData = rec.data;
26 Ext.extend(Ext.form.ComboBoxLister, Ext.form.ComboBox, {
33 hiddenName : false, // set this if you want a , sperated list of values in it for form posting..
34 hiddenListName : false,
36 boxWidth : 200, // use to set the box around the entry..
39 //validateValue : function() { return true; }, // all values are ok!
40 //onAddClick: function() { },
42 onRender : function(ct, position)
45 Ext.form.ComboBoxLister.superclass.onRender.call(this, ct, position);
46 this.wrap.addClass('p-cblist-grp');
47 var cbwrap = this.wrap.createChild(
48 {tag: 'div', cls: 'p-cblist-cb'},
51 if (this.hiddenListName) {
53 this.hiddenEl = this.wrap.createChild({
54 tag: 'input', type:'hidden' , name: this.hiddenListName, value : ''
56 // this.el.dom.removeAttribute("name");
59 this.outerWrap = this.wrap;
61 this.outerWrap.setWidth(this.boxWidth);
62 this.outerWrap.dom.removeChild(this.el.dom);
63 this.wrap.dom.appendChild(this.el.dom);
64 this.outerWrap.dom.removeChild(this.trigger.dom);
65 this.wrap.dom.appendChild(this.trigger.dom);
67 this.trigger.setStyle('position', 'relative');
68 this.trigger.setStyle('vertical-align', 'top');
72 this.adder = this.outerWrap.createChild(
73 {tag: 'img', src: Ext.BLANK_IMAGE_URL, cls: 'x-form-adder', style: 'margin-left:2px'});
75 this.adder.on('click', function(e) {
76 _t.fireEvent('adderclick', this, e);
80 //this.adder.on('click', this.onAddClick, _t);
83 addItem: function(rec)
85 if (this.items.indexOfKey(rec[this.idField]) > -1) {
86 //console.log("GOT " + rec.data.id);
90 var x = new Ext.form.ComboBoxLister.Item({
91 //id : rec[this.idField],
93 nameField : this.nameField,
94 tipField : this.tipField,
98 this.items.add(rec[this.idField],x);
99 // add it before the element..
100 this.updateHiddenEl();
101 x.render(this.outerWrap, this.wrap.dom);
102 // add the image handler..
105 updateHiddenEl : function()
108 if (!this.hiddenEl) {
112 var idField = this.idField;
113 this.items.each(function(f) {
114 ar.push(f.data[idField]);
117 this.hiddenEl.dom.value = ar.join(',');
123 Roo.form.ComboBoxLister.superclass.reset.call(this);
124 this.items.each(function(f) {
128 this.hiddenEl.dom.value = '';
134 return this.hiddenEl ? this.hiddenEl.dom.value : '';
136 setValue: function(v) // not a valid action - must use addItems..
138 if (typeof(v) != 'object') {
142 Roo.each(v, function(l) {
147 validateValue : function(value){
148 return Roo.form.ComboBoxLister.superclass.validateValue.call(this, this.getValue());
154 Ext.form.ComboBoxLister.Item = function(config) {
155 config.id = Roo.id();
156 Roo.form.ComboBoxLister.Item.superclass.constructor.call(this, config);
158 Roo.extend(Roo.form.ComboBoxLister.Item, Roo.BoxComponent, {
161 defaultAutoCreate : {tag: 'div', cls: 'p-cblist-item', cn : [
163 { tag: 'img', width:16, height : 16, src : Roo.BLANK_IMAGE_URL , align: 'center' }
169 onRender : function(ct, position){
170 Roo.form.Field.superclass.onRender.call(this, ct, position);
172 var cfg = this.getAutoCreate();
173 this.el = ct.createChild(cfg, position);
175 this.el.child('img').dom.setAttribute('src', Roo.BLANK_IMAGE_URL);
177 this.el.child('div').dom.innerHTML = this.cb.renderer ?
178 this.cb.renderer(this.data) : String.format('{0}',this.data[this.nameField]);
179 this.el.child('div').dom.setAttribute('qtip', String.format('{0}',this.data[this.tipField]));
181 this.el.child('img').on('click', this.remove, this);
188 this.cb.items.remove(this);
189 this.el.child('img').un('click', this.remove, this);
191 this.cb.updateHiddenEl();