From 3ffffd77ff91488e16684399e1ab4c3e4b3ad214 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 7 May 2024 07:48:07 +0000 Subject: [PATCH] stream_popover: Fix broken move topic to stream popover. `data("typeahead").unlisten()` of move topic to stream popover crashed since we removed `data('typeahead')` in #29973. --- web/src/bootstrap_typeahead.ts | 1 - web/src/composebox_typeahead.js | 2 +- web/src/stream_popover.js | 14 +++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.ts index ccbdbdb76b..32c1cb047b 100644 --- a/web/src/bootstrap_typeahead.ts +++ b/web/src/bootstrap_typeahead.ts @@ -482,7 +482,6 @@ export class Typeahead { for (const event_ of events) { $(this.input_element.$element).off(event_); } - this.input_element.$element.removeData("typeahead"); } resizeHandler(): void { diff --git a/web/src/composebox_typeahead.js b/web/src/composebox_typeahead.js index ee9a444b28..9c106d3213 100644 --- a/web/src/composebox_typeahead.js +++ b/web/src/composebox_typeahead.js @@ -1108,7 +1108,7 @@ export function initialize_topic_edit_typeahead(form_field, stream_name, dropup) $element: form_field, type: "input", }; - new Typeahead(bootstrap_typeahead_input, { + return new Typeahead(bootstrap_typeahead_input, { fixed: true, dropup, highlighter_html(item) { diff --git a/web/src/stream_popover.js b/web/src/stream_popover.js index d15d5ff3d6..24a4a6e955 100644 --- a/web/src/stream_popover.js +++ b/web/src/stream_popover.js @@ -32,6 +32,7 @@ import * as util from "./util"; // that pop up from the left sidebar. let stream_popover_instance = null; let stream_widget_value; +let move_topic_to_stream_topic_typeahead; function get_popover_menu_items(sidebar_elem) { if (!sidebar_elem) { @@ -489,8 +490,12 @@ export async function build_move_topic_to_stream_popover( const $topic_input = $("#move_topic_form .move_messages_edit_topic"); const new_stream_id = Number(stream_widget_value, 10); const new_stream_name = sub_store.get(new_stream_id).name; - $topic_input.data("typeahead").unlisten(); - composebox_typeahead.initialize_topic_edit_typeahead($topic_input, new_stream_name, false); + move_topic_to_stream_topic_typeahead?.unlisten(); + move_topic_to_stream_topic_typeahead = composebox_typeahead.initialize_topic_edit_typeahead( + $topic_input, + new_stream_name, + false, + ); } function render_selected_stream() { @@ -523,7 +528,7 @@ export async function build_move_topic_to_stream_popover( $("#move_topic_modal .dialog_submit_button").prop("disabled", true); const $topic_input = $("#move_topic_form .move_messages_edit_topic"); - composebox_typeahead.initialize_topic_edit_typeahead( + move_topic_to_stream_topic_typeahead = composebox_typeahead.initialize_topic_edit_typeahead( $topic_input, current_stream_name, false, @@ -581,6 +586,9 @@ export async function build_move_topic_to_stream_popover( on_click: move_topic, loading_spinner: true, on_shown: focus_on_move_modal_render, + on_hidden() { + move_topic_to_stream_topic_typeahead = undefined; + }, post_render: move_topic_post_render, }); }