admin-template icon indicating copy to clipboard operation
admin-template copied to clipboard

Focus on inputText with material css.

Open MSet7 opened this issue 7 years ago • 5 comments

Issue Overview

How to set a focus to a p:inputText with material css.

Current Behaviour

Cursor not in inputText 2018-09-26_16-04-40

Expected Behaviour

cursor in inputText when the page is loaded.

How to reproduce

2018-09-26_16-12-03

Just add <p:focus for="email"/> to login starter page (material).

Additional Information
  • AdminFaces version: 1.0.0-RC18
  • PrimeFaces version: 6.2
  • JSF implementation: 2.3

MSet7 avatar Sep 26 '18 14:09 MSet7

Hi, unfortunately the material inputs are processed on page load (see here) hence the initial focus gets lost.

The only workaround I can think now is to set the focus after an initial delay:

$(document).ready(function () {
                setTimeout(function () {
                    $('#email').focus();
                }, 250);
            });

$(document).on("pfAjaxComplete", function () {
                setTimeout(function () {
                    $('#email').focus();
                }, 250);
            });

rmpestano avatar Sep 26 '18 18:09 rmpestano

I know this issue is old, but i used this workaround in a external JS file:

var oldAdminMaterial = adminMaterial;

adminMaterial = function () {
    var x = document.activeElement.id;
    var xValue = document.activeElement.value;
    oldAdminMaterial();
    if (x) {
        document.getElementById(x).value = xValue;
        document.getElementById(x).focus();
    }
} 

with this, the <p:focus/> work in any situation i ever have tested. The value copy is needed for pages when <p:autocomplete/> is the first component in page.

@MSet7 @rmpestano

lfpaz avatar Mar 07 '22 20:03 lfpaz

Hey @lfpaz, can you open a PR?

I'm trying to get the project back on track by updating to the latest PrimeFaces and would be nice to incorporate this fix.

Thank you in advance!

rmpestano avatar Mar 24 '22 06:03 rmpestano

@rmpestano i will open in next days. I'm busy now with the preparations of birth of my son.

lfpaz avatar Mar 29 '22 13:03 lfpaz

Thanks @lfpaz! No rush as I'm also quite busy here.

Cheers!

rmpestano avatar Mar 31 '22 10:03 rmpestano