I have a simple search form application. The form contains input fields, a Search button and a Clear form button.
The Search button triggers a query, which takes values from the input fields and displays results in a table below.
The Clear button uses resetWidget to clear all the form fields and then re-run the search query to display results with no filter.
My issue is that after calling resetWidget, the query runs as if the input fields still have text in them.
I am aware that resetWidget is an asynchronous function that returns a promise. I have tried all manners of async/await and .then() to run the search query after resetWidget has completed clearing the input fields. Nothing works.
How is such a application supposed to be structured? I see no way of accomplishing this simple task.
Thanks!
Hi Ryan,
Calling the query should ideally work. That’s how you build such apps.
Could you share your JS code here? I’ll check if it’s an error in the JS code or in Appsmith.
Abhishek,
I call the following JSObject function with the Clear button onClick method:
clearSearchForm: async () => {
await resetWidget(‘searchForm’, true).then(()=>{
showAlert(“RESET searchForm Complete”);
Query1.run();
});
}
Visually, all forms input fields are cleared, but when Query1 is re-run, the inputField.text values used in the query are equivalent to what they were before resetWidget was called.
If I press the Clear button two times in a row, on the second press Query1 is correctly re-run with all the the input fields being blank.
Thanks!
Hi Ryan,
Thanks for the information. Your JS looks good actually. This is a bug on our end, I’m trying to reproduce it and it seems to occur intermittently. Are you on v1.6.9? I’ll come back to you with an answer on Monday.
Yes, I am on v1.6.9 it’s running inside a docker container with the auto update service.
Hi Ryan, will look into the JS function, but before that: did you try setting the Onclick property of the Clear button to: {{resetWidget("<>")}}?
Hi Ryan,
Scratch that: even with the simpler approach, I could see the the first query run after clearing the form still retained the old search values. Have created an issue for this: [Bug]: Reset on search form does not work for the first time · Issue #11110 · appsmithorg/appsmith · GitHub
We welcome your comments here or directly on the issue.
Thanks,
Rohan
Thanks all for the prompt responses!
I will follow the resolution of the Bug issue on github.
-Ryan