tanthammar / tall-forms

Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.
https://github.com/tanthammar/tall-forms/wiki
MIT License
693 stars 86 forks source link

Undefined variable: temp_key #20

Closed danielbehrendt closed 4 years ago

danielbehrendt commented 4 years ago

I'm always getting errror in v4:

Undefined variable: temp_key (View: vendor/tanthammar/tall-forms/resources/views/components/input.blade.php)

tanthammar commented 4 years ago

Can you please post your component code.

danielbehrendt commented 4 years ago
<?php

namespace App\Http\Livewire\Shop;

use App\Models\Tenant\Shop;
use Livewire\Component;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\TallForm;

class ShopForm extends Component
{
    use TallForm;

    /**
     *
     * @return void
     */
    public function mount(?Shop $model)
    {
        $this->fill([
            'formTitle' => null,
            'showGoBack' => true,
            'wrapWithView' => false,
            'onKeyDownEnter' => '',
            'inline' => false,
        ]);

        $this->mount_form($model);
    }

    /**
     *
     * @return array
     */
    public function fields()
    {
        return [
            Input::make('Name')
                ->rules(
                    $this->model->exists ? 'required|unique:shops,name' : 'required|unique:shops,name,' . $this->model->id
                ),
        ];
    }
}
danielbehrendt commented 4 years ago

@btw: I had to set onKeyDownEnterthis way, otherwise there will be also an error:

Argument 1 passed to Tanthammar\TallForms\Components\Form::__construct() must be of the type string, null given

Removing won't work.

tanthammar commented 4 years ago

Thank you for letting me know about onKeyDownEnter, i released a fix for it.

Regarding your code example, I am unable to reproduce your error.

I do not have the Shop class so I did like this and it is working with and without model.

Route::get('/issue-test/{user?}', \App\Http\Livewire\App\IssueTestForm::class);
<?php

namespace App\Http\Livewire\App;

use App\User;
use Livewire\Component;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\TallForm;

class IssueTestForm extends Component
{
    use TallForm;

    /**
     *
     * @param User|null $user
     * @return void
     */
    public function mount(?User $user)
    {
        $this->fill([
            'formTitle' => null,
            'showGoBack' => true,
            'wrapWithView' => false,
            'inline' => false,
        ]);

        $this->mount_form($user);
    }

    /**
     *
     * @return array
     */
    public function fields()
    {
        return [
            Input::make('Name')
                ->rules(
                    $this->model->exists ? 'required|unique:shops,name' : 'required|unique:shops,name,' . $this->model->id
                ),
        ];
    }
}
tanthammar commented 4 years ago

I also tried to place the component in a view

<livewire:app.issue-test-form :user="\App\User::first()" />
danielbehrendt commented 4 years ago

Thank you for the fix!

Do you have any published views from v3 that might cause the conflict?

No. Removed everything to start from scratch.

Do you have any published config from v3?

No. Removed old config and published the new one.

Can it be the model binding? Should it be (?Shop $shop)?

Model binding looks like this:

<livewire:shop.edit-form :shop="$shop" />

and componentent updated to this:

    public function mount(?Shop $shop)
    {
        $this->fill([
            'formTitle' => null,
            'showGoBack' => true,
            'wrapWithView' => false,
            'inline' => false,
        ]);

        $this->mount_form($shop);
    }

The error also occurs on create.

danielbehrendt commented 4 years ago

Also tested with \App\User. I'm still getting this error. Really strange.

danielbehrendt commented 4 years ago

Maybe it helps to find the problem, the Select field also throws an error:

Undefined variable: options (View: vendor/tanthammar/tall-forms/resources/views/components/select.blade.php)

tanthammar commented 4 years ago

Laravel 7?

danielbehrendt commented 4 years ago

yes

tanthammar commented 4 years ago

Is the component wrapped with another component or view?

danielbehrendt commented 4 years ago

Is the component wrapped with another component or view?

No.

@extends('layouts.tenant', ['title' => 'Shops'])

@section('content')

<div>
    <div class="shadow overflow-hidden sm:rounded-md">
        <div class="px-4 py-5 bg-white sm:p-6">
            <livewire:shop.edit-form :shop="$shop" />
        </div>
    </div>
</div>

@endsection
tanthammar commented 4 years ago

So you have an almost blank app.blade.php and the form?

tanthammar commented 4 years ago

Do you have the Livewire v2 required {{ $slot }} somewhere?

@extends('layouts.base')
@section('body')
    @yield('content')
    {{$slot ?? null}}
@endsection
danielbehrendt commented 4 years ago

Do you have the Livewire v2 required {{ $slot }} somewhere?

@extends('layouts.base')
@section('body')
    @yield('content')
    {{$slot ?? null}}
@endsection

No, that was missing. But has no effect.

tanthammar commented 4 years ago

From the livewire docs

<!-- Before -->
<html>
    <body>
        @yield('content')

        @livewireScripts
    </body>
</html>

<!-- After -->
<html>
    <body>
        {{ $slot }}

        @livewireScripts
    </body>
</html>
danielbehrendt commented 4 years ago

Yes, I've updated this. Also have

<!-- Blade UI Kit Scripts -->
@bukScripts
danielbehrendt commented 4 years ago

@tanthammar Checkboxes are working as expected.

tanthammar commented 4 years ago

I will have to up a new project. But I don't have the time now. Will get back to you in a an hour or two. Have no issues in my local repo.

tanthammar commented 4 years ago

Now I have tested this with a fresh installation of Laravel 7, and while I was at it, I also tested Laravel 8 Jetstream. I had no issues like you are describing. Sorry.

tanthammar commented 4 years ago

@danielbehrendt Have you gotten any further with this? Didn't hear back from you yesterday. Would really like to know where this is coming from.

danielbehrendt commented 4 years ago

@tanthammar This is really strange. Yesterday I've setup a fresh Laravel (going up to v8) and installed all my required packages. Now I've got it running but I do have some other side effect (also with Livewire). I'll have to do so some more debugging, and I'll share any new insights here.

tanthammar commented 4 years ago

@danielbehrendt Thank you for letting me know. Looking forward to your feedback.

tanthammar commented 4 years ago

@danielbehrendt just a thought:

Could you new up a project using Laravel 8 Jetstream, --stack Livewire, no --teams? Don't install any of your components. Do you still have issues? That is what I did when testing yesterday.

Which packages are you using? Maybe there is a Livewire conflict with them? Are you using the latest AlpineJS version? Any errors in console?

danielbehrendt commented 4 years ago

@tanthammar That's really strange. Now that I have a fresh stack (without Jetstream) everything works fine.

One thing I've noticed (already in Livewire v1) is that multiple checkboxes are not getting checked correctly if they were clicked quickly one after the other. Do you have this problem too?

tanthammar commented 4 years ago

Checkboxes: That is due to the network request. Set ->wire('wire:model.defer) You'll loose out on real-time validation but the problem is gone. The field will be validated on submit.

This issue: All is working for you now? Can this issue be closed?

danielbehrendt commented 4 years ago

@tanthammar everything is working now and v2 is looking fantastic! This issue can be closed.

tanthammar commented 4 years ago

@danielbehrendt Did you ever find out what was wrong with your installation, that broke Livewire and this package?

danielbehrendt commented 4 years ago

@tanthammar No, unfortunately (or luckily) not. I'm not able to reproduce the errors.