cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering enter key on press on a fragment

former_member200679
Participant
0 Kudos

Hi,

I want to trigger submit button on pressing enter key.

Above shown is the scenario where i want to trigger submit button on entery key press.

How do i do that?

Please suggest me ways to achieve it.

Thanks,

Saurabh Singh.

Accepted Solutions (1)

Accepted Solutions (1)

karthikarjun
Active Contributor
0 Kudos

Hi Saurabh,

Will this help?

http://jsbin.com/winepe/edit?html,js,output

Use this in dialog:

  afterOpen : function(){

            $(document).bind('keypress', function(e) {

    if(e.keyCode==13){

    e.preventDefault();

            alert('Enter key Pressed');

   sap.ui.getCore().byId("idClose").firePress();

    }

  });

          }

Thanks,

KA

former_member182862
Active Contributor
0 Kudos

Hi All

I have modified Karthik's JSBin to

http://jsbin.com/fefovu/edit?html,js,output

He is very close but we do not want to bind key event to document because when the dialog closes,

we want to binding to get away.

With Karthik's JSBin, close the dialog and then hit enter key again, you will get the alert. we do not want this.

Thanks

-D

Answers (2)

Answers (2)

former_member200679
Participant
0 Kudos

Thanks KA and Dennis for your inputs. Now its working.

Former Member
0 Kudos

Hi,

Try this

$(document).bind('keypress', function(e) {
  
if(e.keyCode==13){
  $
('#submit').trigger('click');
  
}
});

former_member200679
Participant
0 Kudos

I placed the above code with alert() to check.

$(document).bind('keypress', function(e) {

    if(e.keyCode==13){

    e.preventDefault();

            alert('Enter key Pressed');

   $('#submit').trigger('click');

    }

  });

I placed it after opening fragment, and on pressing enter key it shows enter key pressed message, but it is still not triggering the submit button.

Former Member
0 Kudos

Hi,

#submit is the id of the submit button! check id is same. Also scope of variable is visible!

Qualiture
Active Contributor
0 Kudos

I would not use the 'trigger('click')' rather call the function attached to the submit button's press event handler directly!

saivellanki
Active Contributor
0 Kudos

Saurabh,


Try like this:



var oSubmitBtn = sap.ui.getCore().byId("oSubmit");

oSubmitBtn.attachPress({function(){

     //Your code

}});

Regards,

Sai Vellanki.