How to hide keyboard?
I want to hide my ios keyboard after clicking on ElevatedButton()
It should be hidden automatically when moving focus away from TextField, no? Could you provide the repro code please?
Sure! Keyboard is not disappearing on clicking: search_button = ft.ElevatedButton("Поиск", on_click=search, disabled=True)
Full code:
import flet as ft
import requests
import config
def main(page: ft.Page):
page.title = "Kinofun"
page.session.set("old_text", "")
def search(e):
#page.controls.pop()
film = search_box.value
old_film = page.session.get("old_text")
if film != old_film:
page.session.set("old_text", film)
else:
return
while len(page.controls) != 4:
page.remove(page.controls[-1])
r = requests.get(f"https://REDACTED/?title={film}&api_token=" + config.api_key)
if r.status_code == 200:
# scroll
lv = ft.ListView(expand=1, spacing=10, padding=20, )
found_films.value = f"Найдено: {len(r.json()['data'])}"
for film in r.json()["data"]:
lv.controls.append(ft.Text(film[ 'title'], size=22))
lv.controls.append(ft.WebView('https://REDACTED=' + film["imdb_id"], height=200,))
# print(film["iframe_src"])
page.add(lv)
else:
found_films.value = "Фильмы не найдены!"
page.update()
def textbox_changed(e):
if not search_box.value:
search_button.disabled = True
else:
search_button.disabled = False
page.update()
old_text = ""
search_box = ft.TextField(label="Название фильма",on_submit=search, on_change=textbox_changed, expand=True)
search_button = ft.ElevatedButton("Поиск", on_click=search, disabled=True)
found_films = ft.Text(size=30,)
page.add(
# отступ
ft.Text(),
ft.Text(),
ft.Row(
[search_box,search_button,],
),
found_films,
)
ft.app(target=main, web_renderer=ft.WebRenderer.HTML)
The code provided hasimport config which is not part of the main source code. I could not replicate this issue. Either provide the config module or maybe change the source code to replicate the error.
import flet as ft
import requests
def main(page: ft.Page):
page.title = "Kinofun"
page.session.set("old_text", "")
def search(e):
#page.controls.pop()
film = search_box.value
old_film = page.session.get("old_text")
if film != old_film:
page.session.set("old_text", film)
else:
return
while len(page.controls) != 4:
page.remove(page.controls[-1])
r = requests.get(f"https://REDACTED/?title={film}&api_token=")
if r.status_code == 200:
# scroll
lv = ft.ListView(expand=1, spacing=10, padding=20, )
found_films.value = f"Найдено: {len(r.json()['data'])}"
for film in r.json()["data"]:
lv.controls.append(ft.Text(film[ 'title'], size=22))
lv.controls.append(ft.WebView('https://REDACTED/?=' + film["imdb_id"], height=200,))
# print(film["iframe_src"])
page.add(lv)
else:
found_films.value = "Фильмы не найдены!"
page.update()
def textbox_changed(e):
if not search_box.value:
search_button.disabled = True
else:
search_button.disabled = False
page.update()
old_text = ""
search_box = ft.TextField(label="Название фильма",on_submit=search, on_change=textbox_changed, expand=True)
search_button = ft.ElevatedButton("Поиск", on_click=search, disabled=True)
found_films = ft.Text(size=30,)
page.add(
# отступ
ft.Text(),
ft.Text(),
ft.Row(
[search_box,search_button,],
),
found_films,
)
ft.app(target=main, web_renderer=ft.WebRenderer.HTML)
How should the code be tested please?
How should the code be tested please?
if i press "done" on keyboard it disappears, but if i press a search_button = ft.ElevatedButton() then not
@fuad00 At the beginning of the search function, write the following:
def search(e):
search_box.read_only = True
search_box.show_cursor = False
I have the same issue too. On a simple TextField, the IOS keyboard does not hide when clicking on an empty screen or when sliding it down.
The only workaround for me is to use the "Done" button on the IPhone keyboard itself. But unfortunatelly its not visible when using multiline=True, so I am limited to single line inputs for now :(
Single Line
Only way to close by pressing Done ("Fertig" in German), not possible with any clicks or gestures
self.note_field = ft.TextField(
label="Notes",
width=320,
content_padding=10,
adaptive=False,
)
Multiline
Without the "Done" button on the keyboard itself its not possible to close the keyboard
self.note_field = ft.TextField(
label="Notes",
width=320,
content_padding=10,
adaptive=False,
multiline=True,
min_lines=3,
)
More than a year and it was never solved? :( I'm having the same issue. I can't find a way to remove the focus from the textfield so the keyboard will be hide automatically. Any idea?