techouse / select-auto-complete

An auto-completing Laravel Nova search field
MIT License
31 stars 16 forks source link

Repetitive id `single-select` on page; not able to depend on select value #23

Open rela589n opened 3 years ago

rela589n commented 3 years ago

On the screenshots below you can see the problem:

image image

I faced not exactly this problem, but that I am not able to depend on selected value with NovaDependencyContainer (probably because on the input there is no id set. Hope it will be fixed

Steps to reproduce:

Create migration:

      Schema::create('test_subjects', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 128);
        });

Create model.

Create action:


namespace App\Nova\Actions;

use App\Models\TestSubject;
use Epartment\NovaDependencyContainer\NovaDependencyContainer;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Techouse\SelectAutoComplete\SelectAutoComplete;

class AttachTestsQuestionsToTest extends Action
{
    use InteractsWithQueue, Queueable;

    public function handle(ActionFields $fields, Collection $models)
    {
        dump($fields);
        dd($models);
    }

    public function fields()
    {
        return [
            SelectAutoComplete::make('Test Subject2', 'test_subject2')
                ->options(
                    $subjects->mapWithKeys(
                        fn(TestSubject $subject) => [$subject->id => "({$subject->id}) {$subject->name}"]
                    )
                )
                ->displayUsingLabels(),

            NovaDependencyContainer::make(
                [
                    Text::make('second when test_subject is 3')
                ]
            )->dependsOn('test_subject2', 3),
        ];
    }
}