# Clear search box after submit

**URL:** <https://discuss.elastic.co/t/clear-search-box-after-submit/280235>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [August 2, 2021, 3:19pm UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235 "2021-08-02T15:19:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Llermaly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_llermaly/32/92019_2.png) [@Gustavo\_Llermaly](https://discuss.elastic.co/u/Gustavo_Llermaly)\
**Post date:** [August 2, 2021, 3:19pm UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235/1 "2021-08-02T15:19:03Z")

</div>

Hello,

I need to clear the input box value after submitting a search.

I tried the solution of this topic :

> [@Search UI Clear SearchBox Option](https://discuss.elastic.co/t/search-ui-clear-searchbox-option/242120/2):
>
> Hey @M_M. The method you would use to clear the searchbox is setSearchTerm. You would pass an empty string. [https://github.com/elastic/search-ui/blob/master/ADVANCED.md#actions](https://github.com/elastic/search-ui/blob/master/ADVANCED.md#actions)

But if I set setSearchTerm("")

Then:

Filters reseted  
query is removed from url

I only want to remove the text from the box

I tried using shouldClearFilters: false , and reset: false with no success

thanks

---

<div class="post-metadata">

**Author:** ![constancecchen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/constancecchen/32/71762_2.png) [@constancecchen](https://discuss.elastic.co/u/constancecchen)\
**Post date:** [August 9, 2021, 5:31pm UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235/2 "2021-08-09T17:31:50Z")

</div>

It's a little hard to debug this without any code examples, but just to confirm your usage of `shouldClearFilters`, are you definitely doing this?

```auto
setSearchTerm("", { shouldClearFilters: false });

```

As for "query is removed from url" - this is expected behavior. The query string in the URL is tied to the browser input. If you don't want this, you need to [configure your SearchProvider](https://github.com/elastic/search-ui/blob/master/ADVANCED.md#advanced-configuration) with `trackUrlState: false` (although this again has other UX implications - see the docs description).

I'm finding it a little hard to follow your use-case / desired user experience - what _may_ work for you is a custom search input (separate from the default one that comes OOTB from Search UI) that you can "clear" visually without actually triggering an onSearch event.

---

<div class="post-metadata">

**Author:** ![Gustavo\_Llermaly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_llermaly/32/92019_2.png) [@Gustavo\_Llermaly](https://discuss.elastic.co/u/Gustavo_Llermaly)\
**Post date:** [August 9, 2021, 5:46pm UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235/3 "2021-08-09T17:46:32Z")

</div>

Hello and thanks! ,

I ended up setting up the HTML input tag type="search"

`<input type="search"/>`

---

<div class="post-metadata">

**Author:** ![constancecchen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/constancecchen/32/71762_2.png) [@constancecchen](https://discuss.elastic.co/u/constancecchen)\
**Post date:** [August 9, 2021, 6:19pm UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235/4 "2021-08-09T18:19:29Z")

</div>

Hey Gustavo,

Sorry, I'm not sure I'm understanding your response - are you still having issues after doing so or do you have any other follow-up questions?

---

<div class="post-metadata">

**Author:** ![Gustavo\_Llermaly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_llermaly/32/92019_2.png) [@Gustavo\_Llermaly](https://discuss.elastic.co/u/Gustavo_Llermaly)\
**Post date:** [August 15, 2021, 1:52am UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235/5 "2021-08-15T01:52:38Z")

</div>

I'm OK and I will mark my change as the solution.

The requeriment was to clear the search input without affecting the application state, and setting the HTML input to type search added the "x" mark and solved the problem.

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 12, 2021, 1:53am UTC](https://discuss.elastic.co/t/clear-search-box-after-submit/280235/6 "2021-09-12T01:53:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
