Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

@wire and @bind do not work together #99

Open
Sans84 opened this issue Feb 15, 2023 · 0 comments
Open

@wire and @bind do not work together #99

Sans84 opened this issue Feb 15, 2023 · 0 comments

Comments

@Sans84
Copy link

Sans84 commented Feb 15, 2023

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"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant