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 }}
9 Replies
You use
$this->form->fill()
in the mount method?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);
}
}
So where is
$this->form->fill()
?I don't have
$this->form->fill()
😃Add it to
mount()
and see whether that changes somethingnothing 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);
}
inside the console when I click add item
Solution
You should also add a statePath
public array $data = [];
...
return $form
->statePath('data')
->schema($formComponents);
public array $data = [];
...
return $form
->statePath('data')
->schema($formComponents);
working
thanks