-
7 Nov 2011 5:45 PM #1
Answered: Creating select element
Answered: Creating select element
Hello. I'm trying to create a select element which would get added to a panel when I click a button.
After looking at the docs I tried this to create the select node itself:
It does create an element. However, I'm now trying to add an id to it. It is my understanding that I use the set command, but when I try something like this:Code:var a = new Ext.Element('select');
I get an error saying "TypeError: Cannot read property 'setAttribute' of undefined".Code:a.set( { 'id' : 'test' } )
What am I missing?
Thanks you!
Luka
-
Best Answer Posted by skirtle
Which version of ExtJS is this?
new Ext.Element('select') will create a new instance of Ext.Element and attempt to associate it with the HTML DOM element that has the id 'select'. As this doesn't exist it will instead have undefined as its dom property and this will blow up as soon as you try to manipulate it.
There are many, many ways to create a new HTML element in ExtJS. For a panel you'd usually use one of the methods on the panel to inject HTML. e.g. update().
To get an Ext.Element wrapper around a new element you could use:
I would also suggest not trying to use a select element at all. Use an Ext ComboBox or MultiSelect.Code:var a = Ext.get(document.createElement('select'));
-
7 Nov 2011 6:15 PM #2
Which version of ExtJS is this?
new Ext.Element('select') will create a new instance of Ext.Element and attempt to associate it with the HTML DOM element that has the id 'select'. As this doesn't exist it will instead have undefined as its dom property and this will blow up as soon as you try to manipulate it.
There are many, many ways to create a new HTML element in ExtJS. For a panel you'd usually use one of the methods on the panel to inject HTML. e.g. update().
To get an Ext.Element wrapper around a new element you could use:
I would also suggest not trying to use a select element at all. Use an Ext ComboBox or MultiSelect.Code:var a = Ext.get(document.createElement('select'));
-
9 Nov 2011 2:49 PM #3


Reply With Quote