The Android SearchBar implementation fails on the following use case:
1) An external event updates the query text (e.g. the user clicks a link on a page)
2) The user enters the previous query in the search bar
3) NativeScript treats the new query as a no-op (it is not submitted)
In this example we are using the SearchBar as an address bar for a WebView. It is common for a user to click a link on a webpage, at which point we update the text in the SearchBar (without submitting). If the user then attempts to navigate back to the previous page via the address bar the query is not submitted.
The issue is in the following code snippet:
onQueryTextSubmit(query: string): boolean {
const owner = this.owner;
// This code is needed since onQueryTextSubmit is called twice with same query!
if (query !== "" && this[QUERY] !== query) {
owner._emit(SearchBarBase.submitEvent);
}
this[QUERY] = query;
return true;
}
There is no way for a developer to override QUERY when an external event occurs.
Platform: Android
CLI: 2.5.0
Cross-platform modules: 2.5.2
Runtime: 2.5.0
Hi @kimberlysiva
I've tried to recreate the described scenarios with this project but was not able to reproduce the behavior you are talking about. At my side, the submit event is submitting the last updated query even when the query is updated via external event (in the test project I've used a button)
Can you clarify how to reproduce the case you are describing and provide us with a code sample or test project.
Hi @NickIliev
That's actually a perfect sample project, here are the steps to reproduce:
1) Clear the field, type test and submit using the keyboard button.
2) Use your button to update the query, but don't submit!
3) Clear the field, type test and submit using the keyboard button. This time the submit event isn't fired. You can see where it's getting caught up in the code snippet above (the string is equal to the last submitted string, because we never actually submitted the New Query string).
This may seem contrived, but there are many cases where you want to update the text in the SearchBar without actually submitting it. The URL address bar example is the most obvious. When the user clicks a link on a page you want the search bar to reflect the new address, but you don't want to submit it again!
We worked around the issue by creating our own OnQueryTextListener, but it did give us a headache for some time before we figured it out :)
Thanks for recreating this and sharing the sample project - that's amazing developer support right there!
Hey, @kimberlysiva thanks for the detailed explanation!
I can confirm that indeed this case is reproducible with the test project - steps to reproduce described in the post above.
Please what is the status of this issue?
Thanks
no longer reproducible with modules 4.1
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Hi @NickIliev
That's actually a perfect sample project, here are the steps to reproduce:
1) Clear the field, type
testand submit using the keyboard button.2) Use your button to update the query, but don't submit!
3) Clear the field, type
testand submit using the keyboard button. This time the submit event isn't fired. You can see where it's getting caught up in the code snippet above (the string is equal to the last submitted string, because we never actually submitted theNew Querystring).This may seem contrived, but there are many cases where you want to update the text in the SearchBar without actually submitting it. The URL address bar example is the most obvious. When the user clicks a link on a page you want the search bar to reflect the new address, but you don't want to submit it again!
We worked around the issue by creating our own
OnQueryTextListener, but it did give us a headache for some time before we figured it out :)Thanks for recreating this and sharing the sample project - that's amazing developer support right there!