Thread: [DISCUSS] Support focusin and focusout events

Page 1 of 2 1 2 LastLast
  1. #1
    Condor's Avatar
    Condor is offline Ext - Community Support Team Condor is just really nice Condor is just really nice Condor is just really nice Condor is just really nice 19,227 Posts
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    19,227

    Default [DISCUSS] Support focusin and focusout events

    Internet Explorer supports focusin and focusout events. Other browsers don't support this event, but they can be simulated with focus and blur events during capture phase.

    Required changes:
    Code:
    doAdd = function() {
        var ret;
        if (win.addEventListener) {
            ret = function(el, eventName, fn, capture) {
                if (eventName == 'mouseenter') {
                    fn = fn.createInterceptor(checkRelatedTarget);
                    el.addEventListener(MOUSEOVER, fn, (capture));
                } else if (eventName == 'mouseleave') {
                    fn = fn.createInterceptor(checkRelatedTarget);
                    el.addEventListener(MOUSEOUT, fn, (capture));
                } else if (eventName == 'focusin') {
                    el.addEventListener('focus', fn, true);
                } else if (eventName == 'focusout') {
                    el.addEventListener('blur', fn, true);
                } else {
                    el.addEventListener(eventName, fn, (capture));
                }
                return fn;
            };
        } else if (win.attachEvent) {
            ret = function(el, eventName, fn, capture) {
                el.attachEvent("on" + eventName, fn);
                return fn;
            };
        } else {
            ret = function(){};
        }
        return ret;
    }(),
    doRemove = function(){
        var ret;
        if (win.removeEventListener) {
            ret = function (el, eventName, fn, capture) {
                if (eventName == 'mouseenter') {
                    eventName = MOUSEOVER;
                } else if (eventName == 'mouseleave') {
                    eventName = MOUSEOUT;
                } else if (eventName == 'focusin') {
                    eventName = 'focus';
                    capture = true;
                } else if (eventName == 'focusout') {
                    eventName = 'blur';
                    capture = true;
                }
                el.removeEventListener(eventName, fn, (capture));
            };
        } else if (win.detachEvent) {
            ret = function (el, eventName, fn) {
                el.detachEvent("on" + eventName, fn);
            };
        } else {
            ret = function(){};
        }
        return ret;
    }();
    With this addition you can do stuff like:
    Code:
    new Ext.Window({
        title: 'Window',
        width: 300,
        height: 200,
        modal: true,
        layout: 'fit',
        defaultButton: 'focus',
        items: {
            id: 'focus',
            xtype: 'textarea',
            value: 'Try to tab out of this window'
        },
        listeners: {
            render: function(c){
                var focusCmp = Ext.getCmp(c.defaultButton);
                var focusTask = new Ext.util.DelayedTask(focusCmp.focus, focusCmp);
                c.el.on({
                    focusin: function(e){
                        focusTask.cancel();
                    },
                    focusout: function(e){
                        focusTask.delay(10);
                    }
                });
            }
        }
    }).show();
    which would solve the you-can-tab-out-of-a-modal-window problem.
    Condor

  2. #2
    mystix's Avatar
    mystix is offline Ext - Community Support Team mystix will become famous soon enough 6,143 Posts
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,143
    +1e5!!!

    (p.s. i think you've asked for this somewhere before..., but it was probably buried in another thread)


    Sencha Touch - ( Getting Started | Examples | Docs ) / Ext 3.x - ( Docs - Web / Air | Examples | SVN Log )
    HOWTO - ( Report Bugs | Post Proper Code ) / Learn / Saki's Examples

  3. #3
    Condor's Avatar
    Condor is offline Ext - Community Support Team Condor is just really nice Condor is just really nice Condor is just really nice Condor is just really nice 19,227 Posts
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    19,227
    Quote Originally Posted by mystix View Post
    +1e5!!!

    (p.s. i think you've asked for this somewhere before..., but it was probably buried in another thread)
    Good memory. It was in the mouseenter/mouseleave thread.
    Condor

  4. #4
    Animal's Avatar
    Animal is online now Ext - Community Support Team Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough 28,024 Posts
    Join Date
    Mar 2007
    Location
    East Midlands, UK
    Posts
    28,024
    Good idea. Ext's business is to normalize away browser differences.
    ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
    ExtJs consultancy offered. £ 50/hour. Evenings+weekends. animal.software@btinternet.com
    ExtJs training courses being planned: animal.software@btinternet.com

    Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
    Read the docs too: http://extjs.com/deploy/dev/docs/
    Scope: http://extjs.com/forum/showthread.ph...642#post257642

  5. #5
    Join Date
    Apr 2007
    Location
    San Diego->Boston->Brazil
    Posts
    67
    This would be awesome! I hate having to add focus event handlers for every input field. We have some grids that could have many many many input fields which can be time consuming when initially hooking up the handlers with a composite element, so we hardcode a handler in the html (arggghh, I know)

  6. #6
    Animal's Avatar
    Animal is online now Ext - Community Support Team Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough 28,024 Posts
    Join Date
    Mar 2007
    Location
    East Midlands, UK
    Posts
    28,024
    Other browsers support DOMFocusIn and DOMFocusOut so this should be added. It would simplify a lot of things.

    Quote Originally Posted by W3 Event docs
    DOMFocusIn
    The DOMFocusIn event occurs when an EventTarget receives focus, for instance via a pointing device being moved onto an element or by tabbing navigation to the element. Unlike the HTML event focus, DOMFocusIn can be applied to any focusable EventTarget, not just FORM controls.
    • Bubbles: Yes
    • Cancelable: No
    • Context Info: None

    DOMFocusOut
    The DOMFocusOut event occurs when a EventTarget loses focus, for instance via a pointing device being moved out of an element or by tabbing navigation out of the element. Unlike the HTML event blur, DOMFocusOut can be applied to any focusable EventTarget, not just FORM controls.
    • Bubbles: Yes
    • Cancelable: No
    • Context Info: None
    ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
    ExtJs consultancy offered. £ 50/hour. Evenings+weekends. animal.software@btinternet.com
    ExtJs training courses being planned: animal.software@btinternet.com

    Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
    Read the docs too: http://extjs.com/deploy/dev/docs/
    Scope: http://extjs.com/forum/showthread.ph...642#post257642

  7. #7
    Condor's Avatar
    Condor is offline Ext - Community Support Team Condor is just really nice Condor is just really nice Condor is just really nice Condor is just really nice 19,227 Posts
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    19,227
    Quote Originally Posted by Animal View Post
    Other browsers support DOMFocusIn and DOMFocusOut so this should be added. It would simplify a lot of things.
    Opera and WebKit support DOMFocusIn and DOMFocusOut, but Firefox is still missing support (see bugreport).

    Try it on the quirksmode.org.org testpage.
    Condor

  8. #8
    Animal's Avatar
    Animal is online now Ext - Community Support Team Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough 28,024 Posts
    Join Date
    Mar 2007
    Location
    East Midlands, UK
    Posts
    28,024
    It's a mess. Looks like this can't be done for another few years!
    ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
    ExtJs consultancy offered. £ 50/hour. Evenings+weekends. animal.software@btinternet.com
    ExtJs training courses being planned: animal.software@btinternet.com

    Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
    Read the docs too: http://extjs.com/deploy/dev/docs/
    Scope: http://extjs.com/forum/showthread.ph...642#post257642

  9. #9
    Animal's Avatar
    Animal is online now Ext - Community Support Team Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough 28,024 Posts
    Join Date
    Mar 2007
    Location
    East Midlands, UK
    Posts
    28,024
    You can't do it using a capturing listener because that just says that a focus event occurred within that element. Not that focus was outside that element before. It could have been moving from one input to another within that element.

    Same for blur. You can't tell whether the newly focussed element is outside the listener's element. Only that a blur occurred within it.
    ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
    ExtJs consultancy offered. £ 50/hour. Evenings+weekends. animal.software@btinternet.com
    ExtJs training courses being planned: animal.software@btinternet.com

    Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
    Read the docs too: http://extjs.com/deploy/dev/docs/
    Scope: http://extjs.com/forum/showthread.ph...642#post257642

  10. #10
    Condor's Avatar
    Condor is offline Ext - Community Support Team Condor is just really nice Condor is just really nice Condor is just really nice Condor is just really nice 19,227 Posts
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    19,227
    Quote Originally Posted by Animal View Post
    It's a mess. Looks like this can't be done for another few years!
    But capture phase focus and blur events do work on all browsers (except IE), so that's what I used above.
    Condor

Page 1 of 2 1 2 LastLast
© 2006-2010 Ext JS, Inc.