-
10 Nov 2008 10:27 AM #1
How to add a "blank" entry to a ComboBox?
How to add a "blank" entry to a ComboBox?
I want to have a ComboBox that is not editable and has set choices from a store, but I also want them to choose nothing as a valid choice as well.
How do I accomplish this? Ideally I'd like to have a blank entry by default, and when they click on the ComboBox, the blank entry is up top, with the other valid entries below.
thanks!
-
10 Nov 2008 12:04 PM #2
Try something llike this:
Try something llike this:
Try something llike this:
Code:var ds = new Ext.data.JsonStore( { id : 'ds', url : 'some_url', root : 'data', fields: [ { name : 'item_id', type : 'string' }, { name : 'item_desc', type : 'string' }] }); var r = Ext.data.Record.create([ {name: 'item_id', mapping: 'item_id', type: 'string'}, {name: 'item_desc', mapping: 'item_desc', type: 'string'} ]); ds.on('load', function() { var r = new Record({ item_id: '0', item_desc: '-----' }); ds.insert(0, r); });
dlbjr - David L. Bryant Jr.
Owner of
dlbjr Technology Consulting
Web2 System Developer & Consultant
Focused on C.I. - Six Sigma - Shingo - Lean Technologies
dlbjr.consulting@gmail.com
Owner of:
Attractive Graphics - "custom screen printing"
attractivegraphicscsp@gmail.com
-
10 Nov 2008 12:14 PM #3Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
You are creating the record class twice.
Use either:
orCode:var MyRecord = Ext.data.Record.create([ {name: 'item_id', mapping: 'item_id', type: 'string'}, {name: 'item_desc', mapping: 'item_desc', type: 'string'} ]); var ds = new Ext.data.JsonStore( { id: 'ds', url: 'some_url', root: 'data', fields: MyRecord listeners: { load: function() { var r = new MyRecord({ item_id: '0', item_desc: '-----' }); ds.insert(0, r); } });
Code:var ds = new Ext.data.JsonStore( { id: 'ds', url: 'some_url', root: 'data', fields: [ {name: 'item_id', mapping: 'item_id', type: 'string'}, {name: 'item_desc', mapping: 'item_desc', type: 'string'} ], listeners: { load: function() { var r = new (ds.recordType)({ item_id: '0', item_desc: '-----' }); ds.insert(0, r); } } });
-
10 Nov 2008 12:21 PM #4
So is ----- a special string to extjs? Or will it indeed use "------" as the text for the choice? Is there no way to make it blank?
-
10 Nov 2008 2:31 PM #5
It is the text it will show.
It is the text it will show.
var r = new MyRecord({
item_id: '0',
item_desc: '-----'
});
The values '0' and '-----' can be what ever you want
Try '' for both if you like.dlbjr - David L. Bryant Jr.
Owner of
dlbjr Technology Consulting
Web2 System Developer & Consultant
Focused on C.I. - Six Sigma - Shingo - Lean Technologies
dlbjr.consulting@gmail.com
Owner of:
Attractive Graphics - "custom screen printing"
attractivegraphicscsp@gmail.com
-
10 Nov 2008 2:33 PM #6
Oops! Just getting the visual point accross ...
Oops! Just getting the visual point accross ...
Oops! Just getting the visual point accross and not paying attention.
dlbjr - David L. Bryant Jr.
Owner of
dlbjr Technology Consulting
Web2 System Developer & Consultant
Focused on C.I. - Six Sigma - Shingo - Lean Technologies
dlbjr.consulting@gmail.com
Owner of:
Attractive Graphics - "custom screen printing"
attractivegraphicscsp@gmail.com
-
10 Nov 2008 3:54 PM #7
I've tried '' (previous to posting this). EG, I've created an entry with a value of '' for what is displayed, but since ExtJs calculates the size of the pulldown widget by the added heights of the entries in the pulldown, it is incorrect. '' doesn't expand to a full-sized entry, just one that is like 3 or 4 pixels.
So the empty choice exists, but it is impossible to see/click on unless you know its there. I would think the '' choice should be the same size as a choice with text in it.
-
10 Nov 2008 10:42 PM #8Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
You can simply fix that with a different tpl:
(assuming your displayField is named 'text')Code:tpl: '<tpl for="."><div class="x-combo-list-item">{text:defaultValue(" ")}</div></tpl>'
-
11 Nov 2008 3:09 PM #9
-
12 Mar 2009 10:58 AM #10
If I use a '.', I get three entries, one of which is '.' .
Question - if I change '.' to 'BLANKTEXT', how come dropdown has no entries? I get the following error "BLANKTEXT is not defined"
PHP Code:var rec = new store.recordType({EMPID:'0', EMPNAME:'BLANKTEXT'});
store.add(trec);
var cb = new Ext.form.ComboBox({
store: this.TableTypeStore,
valueField:'EMPNAME',
displayField:'EMPNAME',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
editable:false,
tpl: '<tpl for="BLANKTEXT"><div class="x-combo-list-item">{EMPNAME:defaultValue(" ")}</div></tpl>'
});


Reply With Quote