I have a search input field that retrieves results from an API and displays it in a list view.
Is it possible to clear the results without sending an empty search string to the API again?
I want the user to clear the results by clicking the X in the search type input field. Currently I can only show and hide results by using the length function:
dmx-show=“search.value.length()”
But as soon as I start typing in the field my previous results obviously displays again.
Can you reset the form you’re using?
I have found a way to do it. Submitting an empty string to the API to get 0 results back and whilst doing that clearing the search field.
Needs an extra API call, but gets the job done.
Can’t you just do a form reset
1 Like
My search field is not inside a form. Just input and on enter or button press the api call is done.
Couldn’t you just put it in a form for the purpose of clearing the field?
I’m not clearing a field. It is API call data that displays as a list. So somehow I needed the call to clear and seems the only way is to send an empty search string to the API source
You should be able to do a reset of the api, just like a server connect. It might not be in the UI, so try:
ap1.reset()
Tried the api reset and it does not work.
Calls to the api in this case is free, so for now I just send an empty string on success event like this:
api_track.load({track: ‘’})
I see a similar issue discussed over at stackoverflow, only dealing with React response – but nevertheless, a javascript workaround …
thanks @NewMedia - I also saw that one, but due to time constraints and a free api, I took the short cut 
1 Like
So, your own workaround was as you posted?
I am just sending a empty string to API so it brings back nothing. Luckily this is the response this API has on empty searches, so it fit the bill:
api_track.load({track: ‘’})
track is my parameter used for the search field content sent to API
1 Like
this is the result - it clears after adding the songs to the selection list:
1 Like