Skip to content

Submit form on enter #235

@jdavid

Description

@jdavid

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();
        }
      }
    });
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions