list_widget: Check length of JQuery collection instead of collection

itself.

We were checking for the undefined value of `$html_item` but this
variable is always true since `$.find` never returns an undefined value
and it returns a JQuery collection instead.

So we need to check the length of that JQuery collection here to make
sure that the condition works as expected.
This commit is contained in:
Lalit 2023-07-07 15:33:25 +05:30 committed by Tim Abbott
parent ed7588152e
commit d58085dde2
2 changed files with 6 additions and 2 deletions

View File

@ -287,7 +287,7 @@ export function create<Key = unknown, Item = Key>(
return;
}
const $html_item = meta.$scroll_container.find(opts.html_selector(item));
if (!$html_item) {
if ($html_item.length === 0) {
// We don't have the item in the current scroll container; it'll be
// rendered with updated data when it is scrolled to.
return;

View File

@ -674,7 +674,10 @@ run_test("render item", () => {
const regex = new RegExp(`\\<tr data-item=${item}\\>.*?<\\/tr\\>`);
assert.ok(expected_queries.includes(query));
if (query.includes(`data-item='${INITIAL_RENDER_COUNT}'`)) {
return undefined; // This item is not rendered, so we find nothing
// This item is not rendered, so we find nothing so return an empty stub.
return {
length: 0,
};
}
return {
// Return a JQuery stub for the original HTML.
@ -685,6 +688,7 @@ run_test("render item", () => {
called = true;
$container.$appended_data.replace(regex, new_html);
},
length: 1,
};
};