Comments (4)
As I understood:
- You need to store items somewhere. It coud be database,
FsmContext
ormanager.context
(as you already did) - You need to create window getter function. It will read your context or wherever your store your items. Here is an example: https://aiogram-dialog.readthedocs.io/en/latest/widgets.html#select
- To use items from getter should should just set
items="Item"
in your select.
4 Youradd_item
function does not add anything. It replaces saved item in dialog context. May be it is the problem - If you need to do some separate work with separate data, you should start new dialog. For example, in
subdialog.py
second dialog only inputs the name and does not know how it will be used. In your case should either create 2 dialogs or usemanager.switch_to()
instead of starting.
Also, welcome to https://t.me/aiogram_dialog
from aiogram_dialog.
Thanks for your response @Tishka17 , your recommendation helped, but not fully resolve the issue.
Look like I'm made storing of items in context:
async def get_item_list(dialog_manager: DialogManager, **kwargs):
items = dialog_manager.current_context().dialog_data.get('items', [])
if dialog_manager.current_context().dialog_data.get('item', None):
item = dialog_manager.current_context().dialog_data['item']
if len(items) < 5:
items.append(item)
else:
pass
# Notify user that he already have 5 items, and he need to remove something to add new one
return {
"items": items,
}
...
dial_items_manager = Dialog(
Window(
'Your item list',
Select(
Format("{item}"),
items="items",
item_id_getter=operator.itemgetter(1),
id="items",
on_click=show_item,
),
Row(
Button(
Const('Add item to list'),
id="add_item",
on_click=add_item_request,
)
),
Cancel(),
state=ManageItemsSG.show_items,
getter=get_item_list,
),
)
But look like something wrong with adding new items to the list of items, because when I adding some item, var 'item' and 'items' in get_item_list()
are empty.
As you can see in My code:
spoiler upper, I'm using add_item_request()
to change Window to
Window(
Const("Write item which need to add"),
MessageInput(add_item),
state=ManageItemsSG.new_item,
getter=get_item_list,
),
And when I calling add_item()
, it registry my m.text
, but with dialog_manager.current_context().dialog_data["item"]
item not storing as I see. What the better workaround to handle items adding to the global list of items?
It how this look like, item list are empty
from aiogram_dialog.
I do not know, why your getter is modifying context data. It should only read it.
If you want add something to context, do it on your input/button click
from aiogram_dialog.
I used switch_to
in my add_item()
and its helped.
async def add_item(m: Message, dialog: Dialog, dialog_manager: DialogManager):
dialog_manager.current_context().dialog_data["item"] = m.text
await m.answer(f"Your item '{m.text}' added")
await dialog_manager.switch_to(ManageItemsSG.show_items)
The issue can be closed.
from aiogram_dialog.
Related Issues (20)
- ListGroup id HOT 1
- Window events
- ManagerRadio unchecked all HOT 1
- How to use old windows after restarting HOT 4
- show_mode in SwitchTo Widged
- Implementing Multiple Dynamic Counter Widgets with Text Parameters in aiogram-dialog HOT 1
- ShowMode in manager.start() doesn't work as expected by some users HOT 2
- Updating the examples.
- Launching a dialog with the transmission of dynamic data for the status of the checkbox buttons HOT 1
- Start calendar widget with scope Year HOT 1
- Calendar bug while selected date less than 1970 HOT 2
- How i can store data in state using FSMContext HOT 4
- Using payments HOT 1
- Coverage report falied on Jinja widgets HOT 1
- Handling InaccessibleMessage in get_media_id Function
- Best solution for creating different count of buttons
- LinkPreview widget HOT 1
- Reply for button on message HOT 3
- Multiselect и Select с предустановленным состоянием HOT 1
- New rendering protocol
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiogram_dialog.