Repeater not working on custom page

I have repeater inside the custom page
$formComponents[] = Forms\Components\Repeater::make('request-' . $postOrderRequest->id)
->schema([
Forms\Components\FileUpload::make('image')
->label(__('request-builder.post_request.message'))
->disk('s3')
->image()
->avatar()
->required(),

Forms\Components\Textarea::make('response')
->label(__('request-builder.post_request.message'))
->rows(8)
->required(),
])
->minItems(1)
->columns(4)
->maxItems(3);
$formComponents[] = Forms\Components\Repeater::make('request-' . $postOrderRequest->id)
->schema([
Forms\Components\FileUpload::make('image')
->label(__('request-builder.post_request.message'))
->disk('s3')
->image()
->avatar()
->required(),

Forms\Components\Textarea::make('response')
->label(__('request-builder.post_request.message'))
->rows(8)
->required(),
])
->minItems(1)
->columns(4)
->maxItems(3);
{{ $this->form }}
{{ $this->form }}
Solution:
You should also add a statePath ```php public array $data = []; ...
Jump to solution
9 Replies
Dennis Koch
Dennis Koch6mo ago
You use $this->form->fill() in the mount method?
Umar Farooq
Umar FarooqOP6mo ago
here is the full code
class CustomerReview extends BasePage
{
protected static string $view = 'filament.pages.customer-review';

protected static ?string $model = LineItem::class;

public LineItem $record;

public array $settings;

public function mount(
AppSettings $settings,
int $lineItem,
): void
{
$this->record = static::$model::find($lineItem);
$this->settings = $settings->toArray();
}

/**
* @param Form $form
* @return Form
*/
public function form(Form $form): Form
{
$formComponents = [];

foreach ($this->record->postOrderRequests as $postOrderRequest) {
$request = $postOrderRequest->request;

if (!$request->workflow->terminated) {
if ($request->type === 'need_picture_request') {
$formComponents[] = Forms\Components\Repeater::make('request-' . $postOrderRequest->id)
->schema([
Forms\Components\FileUpload::make('image')
->label(__('request-builder.post_request.message'))
->disk('s3')
->image()
->required(),

Forms\Components\Textarea::make('response')
->label(__('request-builder.post_request.message'))
->rows(8)
->required(),
])
->minItems(1)
->columns(2)
->maxItems(3);
} else {
$formComponents[] = Forms\Components\TextInput::make('response-' . $postOrderRequest->id)
->required();
}
}
}

return $form
->schema($formComponents);
}
}
class CustomerReview extends BasePage
{
protected static string $view = 'filament.pages.customer-review';

protected static ?string $model = LineItem::class;

public LineItem $record;

public array $settings;

public function mount(
AppSettings $settings,
int $lineItem,
): void
{
$this->record = static::$model::find($lineItem);
$this->settings = $settings->toArray();
}

/**
* @param Form $form
* @return Form
*/
public function form(Form $form): Form
{
$formComponents = [];

foreach ($this->record->postOrderRequests as $postOrderRequest) {
$request = $postOrderRequest->request;

if (!$request->workflow->terminated) {
if ($request->type === 'need_picture_request') {
$formComponents[] = Forms\Components\Repeater::make('request-' . $postOrderRequest->id)
->schema([
Forms\Components\FileUpload::make('image')
->label(__('request-builder.post_request.message'))
->disk('s3')
->image()
->required(),

Forms\Components\Textarea::make('response')
->label(__('request-builder.post_request.message'))
->rows(8)
->required(),
])
->minItems(1)
->columns(2)
->maxItems(3);
} else {
$formComponents[] = Forms\Components\TextInput::make('response-' . $postOrderRequest->id)
->required();
}
}
}

return $form
->schema($formComponents);
}
}
Dennis Koch
Dennis Koch6mo ago
So where is $this->form->fill()?
Umar Farooq
Umar FarooqOP6mo ago
I don't have $this->form->fill() 😃
Dennis Koch
Dennis Koch6mo ago
Add it to mount() and see whether that changes something
Umar Farooq
Umar FarooqOP6mo ago
nothing change
public function mount(
AppSettings $settings,
int $lineItem,
): void
{
$this->record = static::$model::find($lineItem);
$this->settings = $settings->toArray();

$data = [];

foreach ($this->record->postOrderRequests as $postOrderRequest) {
$request = $postOrderRequest->request;

if (!$request->workflow->terminated) {
if ($request->type === 'need_picture_request') {
$data['response-' . $postOrderRequest->id] = [
'image' => null,
'response' => null
];
} else {
$data['response-' . $postOrderRequest->id] = null;
}
}
}

$this->form->fill($data);
}
public function mount(
AppSettings $settings,
int $lineItem,
): void
{
$this->record = static::$model::find($lineItem);
$this->settings = $settings->toArray();

$data = [];

foreach ($this->record->postOrderRequests as $postOrderRequest) {
$request = $postOrderRequest->request;

if (!$request->workflow->terminated) {
if ($request->type === 'need_picture_request') {
$data['response-' . $postOrderRequest->id] = [
'image' => null,
'response' => null
];
} else {
$data['response-' . $postOrderRequest->id] = null;
}
}
}

$this->form->fill($data);
}
Umar Farooq
Umar FarooqOP6mo ago
inside the console when I click add item
No description
Solution
LeandroFerreira
LeandroFerreira6mo ago
You should also add a statePath
public array $data = [];

...

return $form
->statePath('data')
->schema($formComponents);
public array $data = [];

...

return $form
->statePath('data')
->schema($formComponents);
Umar Farooq
Umar FarooqOP6mo ago
working thanks
Want results from more Discord servers?
Add your server