Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't trigger the event of a non-default button in a modal when the Enter key is pressed #67

Open
DiegoChazki opened this issue Aug 20, 2015 · 0 comments

Comments

@DiegoChazki
Copy link

The issue I am having is when I want to trigger a function or event of a HTML button in the current modal.

function pressKey(){
$('#password').keypress(function(event){

    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13'){
        alert('You pressed a "enter" key in textbox');  
    }
    event.stopPropagation();
});

}

$(document).ready(function() {

var statesdemo = {
        state0: {
            title: '',
            html:/*'<label>First <input type="text" name="fname" value=""></label><br />'+
                '<label>Last <input type="text" name="lname" value=""></label><br />'+*/
                '<section id="merchant-login_ml" class="containerlogin">'+
                    '<div class="container-style_ml" role="form">'+
                    '<h2>Ingresar</h2>'+
                    '<div class="row merchant-icons_ml list-inline">'+
                      '<div class="icon_ml"><span class="persona-icon_ml login-icon_ml"></span>Persona</div>'+
                      '<div class="icon_ml"><span class="empresa-icon_ml login-icon_ml"></span>Empresa</div>'+
                      '<div class="icon_ml"><span class="local-icon_ml login-icon_ml"></span>Local</div>'+
                    '</div>'+
                    '<form class="merchant-form_ml group" name="f" action="../j_spring_security_check" method="POST">'+
                      '<div class="merchant-email_ml">'+
                        '<input id="email" type="email" name="j_username" placeholder="Correo Electrónico" class="form-control" style="height: 40px;">'+
                      '</div>'+
                      '<div class="merchant-password_ml">'+
                        '<input id="password" type="password" name="j_password" placeholder="Contraseña" class="form-control" style="height: 40px;">'+
                        //'<a id="toltip-main" href="forgot-pass.jsp" class="btn btn-lg btn-default no-pass"><span class="tooltip">Olvidé mi contraseña</span>?</a>'+
                      '</div>'+
                      '<div class="merchant-button_ml">'+
                        '<button id="login-button" onclick="pressKey()" class="btn btn-default btn-sm" type="submit">Iniciar Sesión</button>'+
                      '</div>'+
                    '</form>'+
                  '</div>'+
                '</section>',


            buttons: { "A": 1, "B": 2, "Cancel": -1 },
            focus: "input[id='email']",
            submit:function(e,v,m,f){ 
                e.preventDefault();
                if(v==1) $.prompt.goToState('state1');
                if(v==2) $.prompt.goToState('state2');
                if(v==-1)$.prompt.close();
            }
        },
                    ...
     };

    $.prompt(statesdemo);

});

But always that I press the Enter key, it trigger the event of the default button "A", so it goes to another state.
captura de pantalla de 2015-08-20 11 31 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant