laravel-form-components icon indicating copy to clipboard operation
laravel-form-components copied to clipboard

@wire and @bind do not work together

Open Sans84 opened this issue 2 years ago • 0 comments

use Livewire\Component;
use App\Models\Contact;

class ContactForm extends Component
{
    public $contact;

    public function mount(Contact $contact)
    {
        $this->contact = $contact;
        $this->contact->name = 'Simple name';
    }

    public function submit()
    {
        $this->validate();

        $this->contact->save();
    }

    public function rules()
    {
        return [
            'contact.name' => 'required|min:6',
            'contact.email' => 'required|email',
        ];
    }

    public function render()
    {
        return view('livewire.contact-form');
    }
}

view:

<x-form wire:submit.prevent="submit">
    @wire
    @bind($contact)
        <x-form-input name="name" />
        <x-form-input name="email" />
    @endbind
    @endwire

    <x-form-submit>Save Contact</x-form-submit>
</x-form>

After rendering, the "name" input remains empty

expectation: the "name" input = ''Simple name' and binding wire:model="contact.name"

Sans84 avatar Feb 15 '23 17:02 Sans84