TextInput¶
The TextInput widget automatically saving and validating text for later processing in the dialog.
Parameters:
type_factory
: allows for input validation and automatic conversion to the specified type.on_success
: for handling successful input.on_error
: for error handling, will work iftype_factory
throws ValueError.filter
: support aiogram filters.
Code example:
from typing import Any
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import Message
from aiogram_dialog import (
Dialog,
DialogManager,
Window,
)
from aiogram_dialog.widgets.input import TextInput
from aiogram_dialog.widgets.kbd import Next
from aiogram_dialog.widgets.text import Const, Jinja
class SG(StatesGroup):
age = State()
country = State()
result = State()
async def error(
message: Message,
dialog_: Any,
manager: DialogManager,
error_: ValueError
):
await message.answer("Age must be a number!")
async def getter(dialog_manager: DialogManager, **kwargs):
return {
"age": dialog_manager.find("age").get_value(),
"country": dialog_manager.find("country").get_value(),
}
dialog = Dialog(
Window(
Const("Enter your country:"),
TextInput(id="country", on_success=Next()),
state=SG.country,
),
Window(
Const("Enter your age:"),
TextInput(
id="age",
on_error=error,
on_success=Next(),
type_factory=int,
),
state=SG.age,
),
Window(
Jinja(
"<b>You entered</b>:\n\n"
"<b>age</b>: {{age}}\n"
"<b>country</b>: {{country}}\n"
),
state=SG.result,
getter=getter,
parse_mode="html",
),
)
- class aiogram_dialog.widgets.input.text.OnSuccess(*args, **kwargs)¶
- abstract async __call__(message, widget, dialog_manager, data, /)¶
Call self as a function.
- Parameters:
message (Message)
widget (ManagedTextInput[T])
dialog_manager (DialogManager)
data (T)
- Return type:
Any
- class aiogram_dialog.widgets.input.text.OnError(*args, **kwargs)¶
- abstract async __call__(message, widget, dialog_manager, error, /)¶
Call self as a function.
- Parameters:
message (Message)
widget (ManagedTextInput[T])
dialog_manager (DialogManager)
error (ValueError)
- Return type:
Any
- class aiogram_dialog.widgets.input.text.TextInput(id, type_factory=<class 'str'>, on_success=None, on_error=None, filter=None)¶
- Parameters: