Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageEvent #331

Open
ITWeirdRunner opened this issue Jun 4, 2024 · 1 comment
Open

PageEvent #331

ITWeirdRunner opened this issue Jun 4, 2024 · 1 comment

Comments

@ITWeirdRunner
Copy link

ITWeirdRunner commented Jun 4, 2024

Hello! I need help with PageEvent.

I want receive Id in def modal_view from def deliveriy_choice field 'id'
How I can do this?
I have this code

@router.get('/add/delivery', response_model=FastUI, response_model_exclude_none=True)
async def deliveriy_choice(
        session: AsyncSession = Depends(get_async_session)
):
    filters = DeliveryFilter()
    deliveries = await Delivery.get_by(session, filters)
"""I need id from column 'id' """
    return page(
        c.Heading(text='Add', level=2),
        c.Paragraph(text='DB'),
        c.Table(
            data_model=DeliveryTable,
            data=deliveries,
            columns=[
                DisplayLookup(
                    field='id', on_click=PageEvent(
                        name='server-load',
                        context={'id': '{id}'}
                    )
                ),
                DisplayLookup(field='create_at', mode='date'),
                DisplayLookup(field='shop', mode='auto')
            ]
        ),
        c.Div(
            components=[
                c.ServerLoad(
                    path='/mission/delivery/dynamic-content/{id}',
                    load_trigger=PageEvent(name='server-load'),
                    components=[c.Text(text='before')],
                ), ],
            class_name='py-2',
        )
    )


@router.get('/delivery/dynamic-content/{id}', response_model=FastUI, response_model_exclude_none=True)
async def modal_view(
        session: AsyncSession = Depends(get_async_session),
        id: str | None = None
) -> list[AnyComponent]:
"I need id here"
    print(id)
    # delivery = await Delivery.get_by(session, filters=DeliveryFilter(id=id))
    await asyncio.sleep(0.5)
    return [
        c.Paragraph(text=f'Good'),
            ]
@kolanski
Copy link

The issue is that the following PageEvent does not seem to pass any data (like an ID) when triggered:
PageEvent( name='server-load', context={'id': '{id}'} )
In this case, the id field in the context dictionary remains unpopulated, meaning that no actual data binding occurs when the event is fired. I suspect that only the EventGoTo event passes a limited amount of data to the handler.

To address this, we may need a mechanism similar to global event handlers that can capture specific interactions, like the way DisplayLookup can trigger an onclick event and pass relevant data to the backend code for processing.

For example, when invoking PageEvent, the event seems to be initiated exclusively on the Python side but isn’t processed correctly, resulting in no data being passed through. What we need is a solution where the event handler on the front end can trigger backend logic, similar to how typical JavaScript events work (e.g., an onclick event passing data to a backend endpoint).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants