filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.07k stars 2.83k forks source link

Repeater defaults not working #8513

Closed muhajirrr closed 1 year ago

muhajirrr commented 1 year ago

Package

filament/filament

Package Version

v3.0.50

Laravel Version

v10.23.1

Livewire Version

No response

PHP Version

PHP 8.2.6

Problem description

When setting a default value for the Repeater, the default value is not set.

Expected behavior

The default value should be set.

Steps to reproduce

Forms\Components\Repeater::make('nicks')
  ->default([
      ['nick' => 'Jack'],
      ['nick' => 'Josh'],
  ])
  ->schema([
      Forms\Components\TextInput::make('nick')
          ->required(),
  ]),

Reproduction repository

https://github.com/muhajirrr/filament-repeater-defaults-issue

Relevant log output

No response

muhajirrr commented 1 year ago

Hi @danharrin, thanks for your hard work. My previous issue was fixed in the latest release, but i found that the defaults value still doesn't work for repeater with relationship.

The ->default() in the following code is not working.

Forms\Components\Repeater::make('prices')
    ->relationship()
    ->deletable(false)
    ->reorderable(false)
    ->addable(false)
    ->columns(2)
    ->default(
        CustomerType::all()->map(fn (CustomerType $customerType) => [
            'customer_type_id' => $customerType->id,
            'price' => 0,
        ])->toArray()
    )
    ->schema([
        Forms\Components\Select::make('customer_type_id')
            ->relationship('customerType', 'name')
            ->searchable()
            ->preload()
            ->disabled()
            ->required(),

        Forms\Components\TextInput::make('price')
            ->numeric()
            ->required(),
    ]),

I have updated the reproduction repository, you can check it.

danharrin commented 1 year ago

Should be fixed by https://github.com/filamentphp/filament/commit/b7d29f655454e55a2b27ed3aea74aebc351239c8