A library to create forms in aiogram3
Project description
aiogram3-form
A library to create forms in aiogram3
Example
# suppose you import here your router and bot objects
from aiogram import F, types
from aiogram3_form import Form, FormField
class NameForm(Form, router=your_router):
first_name: str = FormField(enter_message_text="Enter your first name please")
second_name: str = FormField(enter_message_text="Enter your second name please", filter=F.text.len() > 10)
age: int = FormField(enter_message_text="Enter age as integer", error_message_text="Age should be numeric!")
@NameForm.submit()
async def name_form_submit_handler(form: NameForm, event_chat: types.Chat):
# handle form data
# also supports aiogram standart DI (e. g. middlewares, filters, etc)
await bot.send_message(
event_chat.id, f"Your full name is {form.first_name} {form.second_name}!"
)
@router.message(F.text == "/form")
async def form_handler(message: types.Message, state: FSMContext):
await NameForm.start(state) # start your form
After submit callback call the state would be automatically cleared.
You can control this state using the following metaclass kwarg
...
class NameForm(Form, clear_state_on_submit=False): # True by default
...
@NameForm.submit()
async def name_form_submit_handler(form: NameForm, state: FSMContext):
# so you can set your exit state manually
await state.set_state(...)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiogram3_form-0.3.3.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file aiogram3_form-0.3.3.tar.gz
.
File metadata
- Download URL: aiogram3_form-0.3.3.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.0 CPython/3.10.8 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ea69214406f4591f4a6cad5f6c9a5eec2ec8d63998490b0d10598c0784dac8 |
|
MD5 | 546715a0941b602ce9e2f1b5fcc135ae |
|
BLAKE2b-256 | 372b0c79caf0e07d938d854d2a8a931c65c193fbbc8f86d0fe6b93294ff4c8fa |
File details
Details for the file aiogram3_form-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: aiogram3_form-0.3.3-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.0 CPython/3.10.8 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 239b250efce7f91667b2c3dc8d9b539ae80e87a019e18422c5cac60b03709af5 |
|
MD5 | b143d745b4d2ab0d77ffa40a146d4188 |
|
BLAKE2b-256 | b760aa455ee0af1e0cdd341af2c2c5d5854fb814e19adb301a4c6308f7401dc9 |