Refresh/Reload Repeater after record create

I have a Page model that has a MorphMany relation with a Url model. I use the saved event when I save a Page model, so that it creates an Url model. This all works okay. Using this mechanism I can create multiple Urls for my Pages and set a primary one.

The problem I have is that when I create a Page, validation is fired. So in the database all is created as it should, but then in my Form it show me the Url field which is required. If I close the EditForm, and reopen the record that is previously created, I see that the Repeater has a value. This is the code:

private static function getSectionModelUrls()
{
    return Section::make()
        ->hidden(fn (?Page $record) => $record === null)
        ->collapsible()
        ->collapsed()
        ->heading('Primaire URL en additionele URL\'s')
        ->schema([
            Repeater::make('modelUrls')
                ->orderColumn('order')
                ->relationship('modelUrls')
                ->schema([
                    TextInput::make('url')
                        ->label(__('strings.fields.slug'))
                        ->required(),
                    Toggle::make('is_primary')
                        ->label('Primary')
                        ->default(false),
                ]),
        ]);
}


I thought that hiding the section initially would solve the problem, but when clicking Save in my form, it kind of refreshed the page and shows the section, with a validation error on the Url field. I would like to save the record and then see the repeater appear with the fields that are already in the database.
Was this page helpful?