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

Setting SearchBar.value to an empty string is not respected #3871

Closed
1 task done
ndonkoHenri opened this issue Aug 25, 2024 Discussed in #3869 · 0 comments · Fixed by #3872
Closed
1 task done

Setting SearchBar.value to an empty string is not respected #3871

ndonkoHenri opened this issue Aug 25, 2024 Discussed in #3869 · 0 comments · Fixed by #3872
Assignees
Labels
controls enhancement Improvement/Optimization

Comments

@ndonkoHenri
Copy link
Contributor

Discussed in #3869

Originally posted by Katsiuk August 25, 2024

Question

Hello!
Can you explain to me exactly how this button works? I need to clear the SearchBar.value in my own function, I mean to set an empty string, but it doesn't update visually, only if I set an empty string with one space, like " ", or some other text.
image_2024-08-25_173908319

Code sample

import flet as ft

def main(page):

    def close_anchor(e):
        text = f"Item {e.control.data}"
        print(f"closing view from {text}")
        anchor.close_view(text)

    def handle_tap(e):
        e.control.open_view()

    def clean_function(e):
        anchor.value = ""  #This doesn't work.
        # anchor.value = " "  # This works and updates visually.
        # anchor.value = "Some text" # And this as well.
        anchor.update()

    anchor = ft.SearchBar(
        view_elevation=4,
        divider_color=ft.colors.AMBER,
        bar_hint_text="Test searchbar",
        view_hint_text="Choose something from the suggestions...",
        on_tap=handle_tap,
        controls=[
            ft.ListTile(title=ft.Text(f"Item {i}"), on_click=close_anchor, data=i)
            for i in range(10)
        ],
    )

    clean_button = ft.ElevatedButton(text="Clear")

    page.add(
        ft.Row(
            alignment=ft.MainAxisAlignment.CENTER,
            controls=[
                ft.OutlinedButton(
                    "Clear searchbar textfield",
                    on_click=clean_function,
                ),
            ],
        ),
        anchor,
    )


ft.app(target=main)

Error message

No response

------------------------------------------------------

  • I have searched for answers to my question both in the issues and in previous discussions.
@ndonkoHenri ndonkoHenri added the help wanted Extra attention is needed label Aug 25, 2024
@ndonkoHenri ndonkoHenri self-assigned this Aug 25, 2024
@ndonkoHenri ndonkoHenri added enhancement Improvement/Optimization controls and removed help wanted Extra attention is needed labels Aug 25, 2024
@ndonkoHenri ndonkoHenri moved this from 🆕 New to 🏗 In progress in Flet Development Aug 25, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Flet Development Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controls enhancement Improvement/Optimization
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant