PDA

View Full Version : getElementsByName does not return a control for Ext.form.field.Checkbox



DerekBrennan20
2 Jun 2014, 8:54 AM
For some controls, calling getElementsByName does work (Ext.form.field.Text and Ext.form.field.ComboBox for example). But for other controls such as Ext.form.field.Checkbox returns undefined. I can't understand why there should b a difference ... the controls are created in the same way. If I examine the input element of the controls that work, I can see that the html has a correctly populated name attribute. For the controls that don't work, this name is empty.

Is this a known issue?

I appreciate that there are other ways to get the control such as Ext.getCmp and getElementById, but for reasons I wont go in to, our client wants to use getElementsByName.

Any ideas appreciated.

Thanks,
Derek Brennan.

DerekBrennan20
3 Jun 2014, 1:56 AM
A bit more on this. The code to replicate is simple. Create a textbox and a checkbox as follows... var checkbox2 = Ext.create('Ext.form.field.Checkbox', { id: 'MyTestCheckBox', name: 'checkbox2' }); var textbox2 = Ext.create('Ext.form.field.Text', { id: 'MyTextBox', name: 'textbox2' }); Add these as items to a panel or something and try to retrieve them as follows... var txt1 = document.getElementsByName('textbox2')[0]; var chk1 = document.getElementsByName('checkbox2')[0]; txt1 is a valid object, whereas chk1 is undefined. I'm using ExtJS 4.2