-
23 Jul 2009 5:23 AM #1
Focus on text Field
Focus on text Field
Hi All,
I have some textfields on a form , after submitting the form if its a failure i want to set focus to a particular text field and select the text all text in the field.
i have tried following but not working:
where raddName is the id as well as the name of textfield.Code:Ext.getCmp('raddName').focus(); Ext.fly('raddName').focus();
Thanks in advance .
-
23 Jul 2009 5:24 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
The first one should work if 'raddName' is the id of the TextField.
-
23 Jul 2009 5:45 AM #3
Focus on text Field
Focus on text Field
Hi Condor,
Thanks for the quick reply, below is my code I can not find it still working , can you please check it for any problem.
Code:function NewRackType(){ var Newrack = new Ext.FormPanel({ labelWidth:90, url:'process.php', frame:true, title:'New Rack Type', defaultType:'textfield', monitorValid:true, items:[{ xtype: 'textfield', fieldLabel: 'Rack Type', labelStyle: 'font-weight:bolder;', name: 'raddName', id: 'raddName', allowBlank: false, width: 200 },{ xtype: 'hidden', name: 'newRack', width: 200, value: '1' }], // All the magic happens after the user clicks the button buttons:[{ text:'Add', formBind: true, handler:function(){ Newrack.getForm().submit({ method:'POST', success:function(){ Ext.Msg.alert('Status', 'PoP Added Sucessfully!', function(btn, text){ if (btn == 'ok'){ Newrack.getForm().reset(); } }); }, failure:function(form, action){ if(action.failureType == 'server'){ obj = Ext.util.JSON.decode(action.response.responseText); Ext.Msg.show({ title: 'Error!', msg: 'Add New Rack Type Failed! <br> '+obj.errors.reason, icon: Ext.MessageBox.ERROR, buttons: Ext.MessageBox.OK }); Ext.getCmp('raddName').focus(); //Ext.fly('raddName').focus(); }else{ Ext.Msg.show({ title: 'Error!', msg: 'Add New Rack Type Failed! <br> Server is Unreachable:'+action.response.responseText, icon: Ext.MessageBox.ERROR, buttons: Ext.MessageBox.OK }); } } }); } },{ text:'Reset', formBind: true, handler: function(){ Newrack.getForm().reset(); } },{ text:'Close', //formBind: true, handler: function(){ win.hide(); } } ] }); var win = new Ext.Window({ layout:'fit', width:350, height: 220, closable: false, resizable: false, plain: true, border: false, items: [Newrack] }); win.show(); }
-
23 Jul 2009 6:00 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Focus the textfield in the fn of the messagebox (the OK button needs the focus first).
-
23 Jul 2009 6:03 AM #5
Hi,
I am a newbie
to EXtJS, can you please help with just putting a code help.
Thanks,
-
23 Jul 2009 6:09 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
(now it gets the focus after you press OK)Code:Ext.Msg.show({ title: 'Error!', msg: 'Add New Rack Type Failed! <br> '+obj.errors.reason, icon: Ext.MessageBox.ERROR, buttons: Ext.MessageBox.OK, fn: function(btn){ Ext.getCmp('raddName').focus(); } });
-
23 Jul 2009 6:13 AM #7
Focus on text Field
Focus on text Field
Thanks Condor ,
Now focus is working but how to select the text in the text field.
Thanks again for your quick help.
-
23 Jul 2009 6:15 AM #8Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Code:Ext.getCmp('raddName').focus(true);
-
23 Jul 2009 6:18 AM #9
Focus on text Field
Focus on text Field
dumb me
, should read the documents .
Thanks for the help Condor, its working now.


Reply With Quote