Time input type

Hi there,

I am playing a little bit with Livewire, and I have a problem with a time input.

When I bind the time input to a model, and I change the value with the keyboard and/or arrows, it resets to the previous(?) value. Does it have to do something with events? It does sends an AJAX request when you change the value.

Are you using the latest version of Livewire:
Yes sir!

Do you have any screenshots or code examples:

<input wire:model="start" type="time" name="start">
namespace App\Http\Livewire;

use Livewire\Component;

class Openingtimes extends Component
{
    public $start;

    ...

    public function render()
    {
        $this->start = '15:00';

        return view('livewire.openingtimes');
    }
    ...
}

Above is a snippet of the code.

Can anyone tell me why it ‘resets’ to the default value on change?

Thanks in advance!

Because you are hard coding it in your render method. Render gets hit every request, so you are reassigning $start to 15:00 every request.

If it’s just a default, assign it when you declare the variable
public $start = '15:00';

1 Like

Doh, you are right! I moved the code to the mount function and it is working afaik.
I wasn’t aware that the render() function was called every time.
Must read docs better I guess.

The snippet I posted was a simplified version of the code.
I wasn’t a default value, but for the sake of an example, good enough to show you what went wrong.

Thank you @xxdalexx