Giter Site home page Giter Site logo

Comments (5)

melloware avatar melloware commented on May 27, 2024 1

That makes sense. Just remove that re focus line...

from primefaces.

haraleib avatar haraleib commented on May 27, 2024 1

Thank you it is working.

from primefaces.

melloware avatar melloware commented on May 27, 2024

Try this version:
pf-11551.zip

Run mvn clean jetty:run and navigate to http://localhost:8080/primefaces-test/

if (PrimeFaces.widget.DefaultCommand) {
    PrimeFaces.widget.DefaultCommand.prototype.init = function(cfg) {
        PrimeFaces.widget.BaseWidget.prototype.init.call(this, cfg);

        // Cache frequently used elements and values
        this.jqTarget = $(PrimeFaces.escapeClientId(this.cfg.target));
        this.scope = this.cfg.scope ? $(PrimeFaces.escapeClientId(this.cfg.scope)) : null;
        var $this = this;
        var scopeEnterKey = 'keydown.' + this.id;

        // Support container elements such as splitButton
        if (this.jqTarget.is(':not(:button):not(:input):not(a)')) {
            this.jqTarget = this.jqTarget.find('button,a').filter(':visible').first();
        }

        // Attach keypress listener to parent form
        var closestForm = this.jqTarget.closest('form');
        closestForm.off(scopeEnterKey).on(scopeEnterKey, {
            scopeEnter: false
        }, function(e, data) {
            data = data || e.data;
            if (($this.scope && data.scopeEnter && data.scopeDefaultCommandId === $this.id) ||
                (!$this.scope && !data.scopeEnter && (e.key === 'Enter'))) {
                var eventTarget = $(e.target);
                // Do not proceed if target is a textarea, button, link, or TextEditor
                if (eventTarget.is('textarea,button,input[type="submit"],a,.ql-editor')) {
                    return true;
                }
                if (!$this.jqTarget.is(':disabled, .ui-state-disabled')) {
                    // focus default command button and click it
                    $this.jqTarget.trigger('focus').trigger(PrimeFaces.csp.clickEvent($this.jqTarget));
                    // re-focus the original input that pressed ENTER
                    eventTarget.trigger('focus');
                }
                e.preventDefault();
                e.stopImmediatePropagation();
            }
        });

        // Add keydown listener to scope if available
        if (this.scope) {
            this.scope.off(scopeEnterKey).on(scopeEnterKey, function(e) {
                if (e.key === 'Enter') {
                    closestForm.trigger(e, {
                        scopeEnter: true,
                        scopeDefaultCommandId: $this.id
                    });
                    e.stopPropagation();
                }
            });
        }

    }
}

from primefaces.

haraleib avatar haraleib commented on May 27, 2024

@melloware I tried it. I think it is a nice idea to return the focus, do you think this can result in errors if the commandButton updates the content or forwards/redirects to another page, so that the eventTarget is not available any more?

Nevertheless, returning the focus results in a loop where, the

  • 1 request is from the inputText
  • 2 request is from the commandButton
  • 3 ... n requests are from the inputText

image

The line which is returning the focus and causing the loop
image

from primefaces.

melloware avatar melloware commented on May 27, 2024

Awesome I updated my PR to remove that line as well.

from primefaces.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.