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

Form field initial values not resetting when GoToEvent occurs #298

Open
jimkring opened this issue May 1, 2024 · 0 comments
Open

Form field initial values not resetting when GoToEvent occurs #298

jimkring opened this issue May 1, 2024 · 0 comments

Comments

@jimkring
Copy link
Contributor

jimkring commented May 1, 2024

I'm trying to implement a Search form. I want to also have a Clear button that will reset the text input field of the form:

Here is the form model, which has a single query string field:

Form Model Definition

class SearchForm(BaseModel):
    query: Optional[str] = Field(None, title=' ', description='Use keywords to search')

For form is a ModelForm component:

Form Component in Page

c.ModelForm(model=SearchForm, display_mode='default', submit_url='/api/search/', method='POST', initial={'query': q}, class_name='+ mb-2')

The search endpoint sets the q variable in my page:

Form's POST Endpoint

@router.post('/api/search/', response_model=FastUI, response_model_exclude_none=True)
async def big_form_post(form: Annotated[SearchForm, fastui_form(SearchForm)]):
    return [c.FireEvent(event=GoToEvent(url='/search/', query={'q': form.query}))]

I tried to create a button that clears the search box with an on_click event that invokes GoToEvent(url='/search/', query={'q': ""}):

Clear Search Button

c.Button(text='Clear Search', on_click=GoToEvent(url='/search/', query={'q': ""}))

When I click the button, I can see that the request gets processed and theq variable is correctly set to an empty string.

However, the form field doesn't get reset to an empty string.

Any ideas what I could try? Might this be a bug?

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

1 participant