Livewire Input Field Not Initializing with Data
Hello everyone,
I've been working on a Livewire component for configuring system settings in a Laravel application and encountered an issue where the input fields were not displaying their initial values, despite being properly set up in the component's state.
In my Livewire component, I was setting the initial values for anniversary_code_validity and newsletter_code_validity in the mount() method from my model Configuration. Despite the values being properly assigned and confirmed through logging / dd / dump, the input fields in my form were rendered without any values.
Code Example:
public function mount()
{
$config = Configuration::first();
$this->anniversary_code_validity = $config->anniversary_code_validity;
$this->newsletter_code_validity = $config->newsletter_code_validity;
}
Blade Template:
<input type="number" class="form-control" id="anniversary_code_validity"
wire:model="anniversary_code_validity">
@dump('anniversary_code_validity'); // this shows the correct value on my view
If i add the value attribute to the input fields in the Blade template:
<input type="number" class="form-control" id="anniversary_code_validity"
wire:model="anniversary_code_validity" value="{{ $anniversary_code_validity }}">
It works, but it doesn't feel right.
Is there a more "Livewire" way to ensure the input fields are initialized correctly without manually setting the value attribute? Could this issue be related to a potential bug in Livewire, or is it more likely a conflict or mistake in my setup?
Livewire version : 2.11
Please or to participate in this conversation.