1

I know there some posts similar like this one on the page, but none of the posted answers worked for me. I have a login form with jsf and I use ajax to reload a panel depending on the user attributes after login. I have two problems: The first problem is that I can´t make my browser to prompt to save password. I read that if you use ajax for a security reason browsers doesnt store password, is any way to force this? or any workaround? Problem two (I think simpler) I want to execute the button on enter key. This is my form:

<h:form id="formLogin">
        <h:panelGroup id="pgLogin" layout="block">
            <h:panelGroup id="panel1" rendered="#{empty login.sessionUsuario}" layout="block">
                <h:inputText type="text" id="userLogin" value="#{login.usuario}" autocomplete="on">
                </h:inputText>
                <h:message for="userLogin" class="error"/>
                <h:inputSecret type="password" id="passwordLogin" value="#{login.password}" autocomplete="on">
                </h:inputSecret>
                <f:ajax render="pgLogin loginOK" execute="@form" >
                    <h:commandLink id="btlogin" action="#{login.iniciarSesion}">
                        <button type="button" id="logIn">Log In</button>
                    </h:commandLink>
                </f:ajax>
            </h:panelGroup>
        </h:panelGroup>
    </h:form>
user3285427
  • 71
  • 2
  • 6
  • Interesting : http://stackoverflow.com/questions/14126672/jsf-resets-fields-when-doing-an-ajax-update – Omar Jan 15 '17 at 20:05

1 Answers1

0

I assume you want to invoke the submit button from either of the input fields. Add this script to your page:

<script>
    var triggerSubmit = function(event){
       if (event.keyCode == 13) {
            document.getElementById('btlogin').click();
       }
    };

    document.getElementById('userLogin')
        .addEventListener('keypress', triggerSubmit);

    document.getElementById('passwordLogin')
        .addEventListener('keypress', triggerSubmit);
</script>
Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63