I am trying to use .keypress() because I need for the users to be able to hit enter and the button to be clicked on my modal (this button closes the modal). When I code:
$(document).keypress(function () { console.log('keypress'); });
it works but I obviously can’t have it on the document or else or hitting enter would close my modal at any time. So I tried this (bc this had the id of my modal):
$('#confirmModal').keypress(function () { console.log('keypress'); });
But it does not work. So I thought well maybe its because the modal does not exist yet on the page until the user clicks cancel so I tried:
$('#AddLeadGeneral').on('keypress', '#confirmModal', function () {
console.log('.on keypress');
});
But this does not work. Interestingly, enough if I replace ‘keypress’ with ‘click’ in my .on() function it works. I think I just do not know enough about keypress to work with it properly. Basically, for my modal when one hits enter the default button should be ‘No’ so that should close the modal as if they clicked it. Does anyone know how to make this work?
Steps: Click cancel at the bottom of the page, then hit enter or click No in the modal and you will see the difference in affects.
https://scrmqa.autobase.net/Opportunity/General?leadType=FloorUp&searchType=CustomerSearch&firstName=&lastName=x&phone=&address=&postalCode=&emailAddress=&
Keypress is not the best thing to use, because it don’t return on every character the same as keydown or keyup.