Skip to content

Commit f7847c1

Browse files
committed
Avoid endless loop in modal inline edit submit
Ensure that the submit event has a defined submitter property to avoid an endless loop between the form submit event listener, submitInlineEdit, and htmx.trigger.
1 parent 2009034 commit f7847c1

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

share/static/js/util.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,20 +1978,24 @@ jQuery(function () {
19781978
jQuery(this).closest('form').data('changed', true);
19791979
});
19801980
document.querySelector('#dynamic-modal form').addEventListener('submit', function(evt) {
1981-
evt.preventDefault();
1982-
1983-
document.querySelectorAll('#dynamic-modal form textarea.richtext').forEach((textarea) => {
1984-
const name = textarea.name;
1985-
if ( RT.CKEditor.instances[name] ) {
1986-
if ( RT.CKEditor.instances[name].getData() !== textarea.value ) {
1987-
RT.CKEditor.instances[name].updateSourceElement();
1988-
jQuery(textarea.closest('form')).data('changed', true);
1981+
// if form was submitted using htmx.trigger in submitInlineEdit evt.submitter is undefined
1982+
// in that case allow default form submit otherwise it creates an endless loop:
1983+
if ( evt.submitter !== undefined ) {
1984+
evt.preventDefault();
1985+
1986+
document.querySelectorAll('#dynamic-modal form textarea.richtext').forEach((textarea) => {
1987+
const name = textarea.name;
1988+
if ( RT.CKEditor.instances[name] ) {
1989+
if ( RT.CKEditor.instances[name].getData() !== textarea.value ) {
1990+
RT.CKEditor.instances[name].updateSourceElement();
1991+
jQuery(textarea.closest('form')).data('changed', true);
1992+
}
19891993
}
1994+
});
1995+
if ( jQuery('#dynamic-modal form').data('changed') ) {
1996+
cell.addClass('editing');
1997+
submitInlineEdit(jQuery('#dynamic-modal form'), cell);
19901998
}
1991-
});
1992-
if ( jQuery('#dynamic-modal form').data('changed') ) {
1993-
cell.addClass('editing');
1994-
submitInlineEdit(jQuery('#dynamic-modal form'), cell);
19951999
}
19962000
});
19972001
});

0 commit comments

Comments
 (0)