Do we have to set public properties individually for a large form

What seems to be the problem:
My inputs are all blank in the view.

Are you using the latest version of Livewire: I am using 0.6.0

Do you have any screenshots or code examples:

In VIEW (the form has 38 fields)

    <div class="w-1/3">
            <label class="tw-label">First Name< /label>
            <input type="text" class="tw-input" wire:model="user.first_name">
         <div>

COMPONENT

    <?php

    namespace App\Http\Livewire\Staff;

    use App\Models\Department;
    use App\Models\Office;
    use App\User;
    use Livewire\Component;

    class StaffEditor extends Component
    {
        public $user;
        public $userID = null;
        public $defaultPW = null;

        public function mount($id)
        {
            $this->userID = $id;
            $fetched = User::query()
                ->with('departments', 'manager', 'office')
                ->whereId($id)
                ->first();

            $cleanLastName = ucfirst(preg_replace("/[^A-Za-z]/", '', strtolower($fetched->last_name)));
            $dpw = '!' . $cleanLastName . '@uam';
            $this->defaultPW = $dpw;

            $this->user = $fetched;
        } // end function

        public function render()
        {
            return view('_livewire.staff.staff-editor');
        } // end function

        /*******************************/
        public function getManagersProperty()
        {
            return User::whereCanManage(true)->orderBy('last_name')->get();
        } // end function

        public function getOfficesProperty()
        {
            return Office::all();
        } // end function
    }

In one of my apps I also have used Liveware on a long form. And for each field I have set an individual public property. Besides (real-time) validation this was also necessary because I wanted to be able to format inputs (email/phone number) or requesting additional info (get address using zipcode). Didn’t manage to do this any other way. It makes your component code a bit long and ugly, but so be it.

2 Likes

Thanks Erik. You’ve been a great help!

Do you know how we close a discussion on here?

1 Like