Because the fields are outside the <form> element, pressing the Enter key does not submit the form.
This is my workaround:
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('django-formset').forEach(formset => {
formset.addEventListener('keypress', function(event) {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
// Find the submit button and click it
const submitButton = formset.querySelector('button[type="submit"], input[type="submit"]');
if (submitButton) {
submitButton.click();
}
}
});
});
});
Because the fields are outside the
<form>element, pressing the Enter key does not submit the form.This is my workaround: