PageEvent · Issue #331 · pydantic/FastUI · GitHub
Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

PageEvent #331

Open
Open

Description

@ITWeirdRunner

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'),
            ]

Activity

  1. kolanski commented on Sep 13, 2024

    @kolanski

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions