Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muuucho's avatar
Level 11

Reset a select field to first option

There is a nice feature in HTML that creates a reset button inside an input field. You just replace <input type="text"> with <input type="search"> and a reset button like an "X" will appear when you start to type in the input field. However, I also have a filter field that is a and <select type="search"> doesn't give any reset button. Maybe it is not possible in HTML so i wonder if it is possible in Livewire? In my case i like it to reset to the first option, in my case <option>Filter on tags...</option>

0 likes
1 reply
LaryAI's avatar
Level 58

In HTML, there is no built-in reset button for <select> fields. However, you can achieve this functionality using JavaScript or a JavaScript framework like Livewire.

Here's an example of how you can reset a <select> field to its first option using Livewire:

<div>
    <select wire:model="selectedOption">
        <option value="">Filter on tags...</option>
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
        <option value="option3">Option 3</option>
    </select>

    <button wire:click="resetSelect">Reset</button>
</div>

In your Livewire component, you would have the following code:

use Livewire\Component;

class MyComponent extends Component
{
    public $selectedOption = '';

    public function resetSelect()
    {
        $this->selectedOption = '';
    }

    public function render()
    {
        return view('livewire.my-component');
    }
}

When the "Reset" button is clicked, the resetSelect method is called, which sets the $selectedOption property to an empty string. This will reset the <select> field to its first option, which has a value of an empty string.

Note: Make sure you have Livewire properly set up in your Laravel application before using this solution.

Please or to participate in this conversation.