Skip to content

Commit b42fa88

Browse files
authored
Fix submitting the form using Enter key.
Submitting the form using enter key (triggering submit event via input field) bypassed the isFormValid logic and redirected to success_url if form_valid, or to raw form with errors if form_invalid. This fixes that.
1 parent c3b2052 commit b42fa88

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bootstrap_modal_forms/static/js/jquery.bootstrap.modal.forms.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ https://github.com/trco/django-bootstrap-modal-forms
2121
$(settings.submitBtn).on("click", function (event) {
2222
isFormValid(settings, submitForm);
2323
});
24+
// Support submition on form fields
25+
$(settings.modalForm).on("submit", function (e) {
26+
if (e.originalEvent !== undefined) {
27+
e.preventDefault();
28+
isFormValid(settings, submitForm);
29+
return false;
30+
}
31+
});
2432
// Modal close handler
2533
$(settings.modalID).on("hidden.bs.modal", function (event) {
2634
$(settings.modalForm).remove();
@@ -169,4 +177,4 @@ https://github.com/trco/django-bootstrap-modal-forms
169177
return this;
170178
};
171179

172-
}(jQuery));
180+
}(jQuery));

0 commit comments

Comments
 (0)