Infinite loop in widget.js when used in an inline with an empty/zero-length queryset.
See original GitHub issueThis particular loop goes on forever: https://github.com/gregmuellegger/django-sortedm2m/blob/master/sortedm2m/static/sortedm2m/widget.js#L22
while (!label || !label.length) {
currentElement = currentElement.parent();
label = currentElement.siblings('label');
}
It only happens if the item that needs sorting is empty and uses a Django admin inline. It works fine if it’s not a Django admin inline - when viewing it from that model’s page on the Django admin.
I’ve added logging inside the loop:
while (!label || !label.length) {
console.log("here");
console.log(label);
console.log(currentElement);
currentElement = currentElement.parent();
label = currentElement.siblings('label');
}
This is the output:
here
undefined
[ul.sortedm2m-items.hide.sortedm2m, context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div.sortedm2m-container, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div.related-widget-wrapper, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[td.field-deals, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[tr#deal_categories-0.form-row.row1.has_original.dynamic-deal_categories, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[tbody, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[table, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[fieldset.module, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div.tabular.inline-related.last-related, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div#deal_categories-group.inline-group, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[form#hotel_form, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div#content-main, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div#content.colM, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[div#container, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[body.flat-theme.app-hotels.model-hotel.change-form, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[html, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
[document, prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[1], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
It then goes on to print this forever:
here
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
[prevObject: jQuery.fn.init[0], context: ul.sortedm2m-items.hide.sortedm2m]
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Infinite loop in widget.js when used in an inline with an empty ...
It only happens if the item that needs sorting is empty and uses a Django admin inline. It works fine if it's not...
Read more >Django Infinite scroll using Django Paginate repeating the ...
In the templates I replaced post_list with page_obj see below code. That did it {% if post_list.has_next %} <a class="infinite-more-link" ...
Read more >Infinite Loops in Javascript - Flexiple
Such a loop is called an infinite loop. In this article, we are going to see how to detect and escape infinite loops....
Read more >Infinite loop when calling hidden button via OnBlur | OutSystems
In a v10 web app I have a hidden button that is called using the following Javascript when an OnBlur is triggered via...
Read more >JavaScript while Loop - W3Schools
The while loop loops through a block of code as long as a specified condition is true. Syntax. while (condition) { // code...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just check ul element on empty in iterateUl . Works fine for me.
Fixed by #170