How can I disable pressing enter on the keyboard to save a record on Add/Copy and Edit pages?
Disable Enter to save?
-
- User
- Posts: 11730
You may use jQuery .keydown() to detect Enter key, and then call preventDefault
event.
-
- User
- Posts: 171
Thanks!
This did the trick:
Client Scripts -> Table-Specific -> Add/Copy Page/Edit Page -> Startup Script
// Prevent saving when enter is pressed
$(document).ready(function() {
$(window).keydown(function(e){
if(event.keyCode == 13) {
e.preventDefault();
return false;
}
});
});
-
- User
- Posts: 171
Bringing back this thread because it appears the code I posted above prevents pressing enter to add line breaks in textarea fields which is a problem. Any ideas around this?
-
- User
- Posts: 171
Thank you for pointing me in the right direction! e.srcElement always returned undefined but I found e.target worked so I changed the code above to:
// Prevent saving when enter is pressed
$(document).ready(function() {
$(window).keydown(function(e){
if (e.target.type !== "textarea"){
if(event.keyCode == 13) {
e.preventDefault();
return false;
}
}
});
});
This ignores textarea fields. All is working now.