Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchBar stopped working #3602

Closed
1 task done
mfxbe opened this issue Jul 4, 2024 · 4 comments
Closed
1 task done

SearchBar stopped working #3602

mfxbe opened this issue Jul 4, 2024 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@mfxbe
Copy link

mfxbe commented Jul 4, 2024

Duplicate Check

Describe the bug

With the update from Flet 0.22.1 to 0.23.X the SearchBar stopped working. The dropdown/list with results just doesn't open anymore. No error shown.

I've put a part of the code I'm using below but it also stopped working for me if I just follow the example from the docs.

Code

class ExtraSearchBar(ft.SearchBar):
	def __init__(self, hint, extras):
		super().__init__()
		self.extras = []
		self.lv = ft.ListView()

		self.extras = extras
		self.bar_bgcolor=ft.colors.BACKGROUND
		self.view_hint_text="Extras"
		self.bar_hint_text=hint
		self.controls=[self.lv]
		self.on_change=self.handle_change
		
		index = 0
		for i in self.stations:
			y = i["name"]
			self.lv.controls.append(ft.ListTile(title=ft.Text(f"{y}"), on_click=self.close_anchor, data=y))
			index = index + 1
			if index >= 30:
				break;

To reproduce

  1. Use the SearchBar example from the docs
  2. Run it & click on the searchbar
  3. Searchbar gets focus but no "result" list is shown

Expected behavior

No response

Screenshots

No response

Operating System

Linux

Operating system details

Debian sid

Flet version

0.23.2

Regression

Yes, it used to work in a previous Flet version (please specify the version in additional details)

Suggestions

No response

Additional details

Worked in Flet 0.22.1

@ndonkoHenri
Copy link
Contributor

Sorry for that, we forgot to mention a change in this Control.
From now on, the dev (you) is responsible for opening the searchbar when it is pressed. (ref)

Briefly: you just need to call search_bar.open_view() in your on_tap event handler

Will update documentation code.

@ndonkoHenri ndonkoHenri added the documentation Improvements or additions to documentation label Jul 4, 2024
@ndonkoHenri ndonkoHenri self-assigned this Jul 4, 2024
@mfxbe
Copy link
Author

mfxbe commented Jul 5, 2024

Thank you for your answer and the hint with the tab_handler. But I'm still not completely sure how I should solve it.

As you can see in the code example above I use a class to build a "widget" based on the SearchBar. If I put self.on_tap = self.open_view() in there it leads to the following issue:

AssertionError: Control must be added to the page first.

I would really prefer not to be forced to set up that event handler for each instance but I see no way to do that here. Am I missing something?

Update:
For now I managed to bypass the problem by setting self.on_change = self.handle_change and adding this function within the class:

def handle_tap(self, _e):
	if self.page is not None:  self.open_view()

@ndonkoHenri
Copy link
Contributor

adding this function within the class:

Yep! As I said, the only change is to call that method in the on_tap handler.

If I put self.on_tap = self.open_view() in there it leads to the following issue: AssertionError: Control must be added to the page first.

You are not doing it right, that's why it fails.
You could have done it like this Instead: self.on_tap = lambda e: self.open_view(), or you create a method for the on_tap (handle_tap, as you did) and call open_view() in there.

@mfxbe
Copy link
Author

mfxbe commented Jul 8, 2024

Ah alright, I see. That's the right way to do it. So the only thing missing indeed is up-to-date documentation, no issues in code. Thanks again.

@ndonkoHenri ndonkoHenri moved this from 🆕 New to 🏗 In progress in Flet Development Jul 20, 2024
@ndonkoHenri ndonkoHenri moved this from 🏗 In progress to ✅ Done in Flet Development Jul 23, 2024
@ndonkoHenri ndonkoHenri closed this as completed by moving to ✅ Done in Flet Development Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Archived in project
Development

No branches or pull requests

2 participants