3

What I am trying to do is getting some data from DB and showing it in Input Value fields but here the problem is that when I use wire:model='some_input_name' the value does not show up. And if I remove the wire:model it shows the value

the code:

<div class="form-group">
    <label for="site_name">Site Name</label>
    <input wire:model='site_name' type="text" name="site_name" id="site_name"
          class="form-control"
          placeholder="Site Name" value="{{$settings->site_name}}">
    </div>

Is there anything wrong here?? What is the correct way to show value while binding the input field with livewire component?

Abdullah
  • 123
  • 1
  • 1
  • 11

2 Answers2

10

Remove value="{{ $settings->site_name }}" from your <input>, and use the following code in your component's mount() method:

$this->site_name = $settings->site_name;

This will preserve the two-way data binding, whilst letting you set an initial value.

Dan Harrin
  • 889
  • 6
  • 17
2

The best way to achieve this is to set an array of rules in your component, such as

$rules = [
 'settings.site_name' => 'required'
];

This validates you field values and allows them to be displayed. Futher reading is here in the livewire docs.

damask
  • 529
  • 4
  • 17