PDA

View Full Version : How to find the field that has the focus once submit button is clicked?



varmaj80
11 Jun 2014, 1:19 PM
Hello,

I am using ExtJs 4.2. I have a form which has some 15-20 fields which are text and combo boxes. Now when I click the submit button on this form, I need to check which field has the focus at the time of submitting the form. How do I know that?. Is there a way to know which field has focus during form submission?.

mdnaveed42
11 Jun 2014, 10:29 PM
Hi,

Added a fiddle for you.. Click here (https://fiddle.sencha.com/#fiddle/6ji) to check.


Thanks,
MD Naveed
\m/

Piruthu
12 Jun 2014, 2:27 AM
Focus event has an EventObject parameter, you could use EventObject's getRelatedTarget (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.EventObject-method-getRelatedTarget)() to find the field.

Try adding this listener to the Submit button:

listeners: {
focus : function(btn, The, eOpts){
console.log(' Field Ref > ', The.getRelatedTarget());
console.log(' name > ', The.getRelatedTarget().name);
}
}