Persistent TextField prefix #3185
-
QuestionIs there a way to make the Problem Showcase showcase-prefix.mp4Code sampleimport flet as ft
class TagsInput(ft.UserControl):
def __init__(self):
super().__init__()
self.tags = [] # hold the tags
def build(self):
self.text_field = ft.TextField(on_submit=self.add_tag, dense=False)
self.tags_container = ft.Row(vertical_alignment=ft.CrossAxisAlignment.END)
return self.text_field
def add_tag(self, e):
if tag_text := e.control.value.strip():
tag = ft.TextButton(
content=ft.Row([ft.Text(tag_text), ft.Icon(ft.icons.CLOSE, size=15)]),
on_click=lambda e, tag_text=tag_text: self.remove_tag(tag_text),
style=ft.ButtonStyle(
bgcolor=ft.colors.GREEN_600, color=ft.colors.WHITE
),
)
self.tags.append(tag_text)
self.tags_container.controls.append(tag)
self.text_field.value = ""
self.text_field.prefix = self.tags_container
self.text_field.update()
def remove_tag(self, tag_text):
self.tags.remove(tag_text)
self.tags_container.controls.clear()
for tag in self.tags:
self.tags_container.controls.append(
ft.TextButton(
content=ft.Row([Text(tag_text), ft.Icon(ft.icons.CLOSE, size=15)]),
on_click=lambda e, tag_text=tag_text: self.remove_tag(tag_text),
style=ft.ButtonStyle(
bgcolor=ft.colors.GREEN_600, color=ft.colors.WHITE
),
)
)
self.text_field.update()
def main(page: ft.Page):
tags_input = TagsInput()
page.add(tags_input)
ft.app(target=main) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
Vivekananda-Mullangi
May 3, 2024
Replies: 1 comment
-
currently there is no way for prefix property to be persistent the best you can do is use stack to overlay one on another or keep the tags under/over the textfield |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Bbalduzz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
currently there is no way for prefix property to be persistent the best you can do is use stack to overlay one on another or keep the tags under/over the textfield