F
Filament10mo ago
Fly_Moe

Form with optional repeater failing to save

Hello everyone, I have an optional repeater inside a form. If it's filled out, it will save correctly with no error. However, if the repeater is left blank it will error out with this error:
Cannot insert the value NULL into column 'Name', table 'Detail'; column does not allow nulls. INSERT fails.
Cannot insert the value NULL into column 'Name', table 'Detail'; column does not allow nulls. INSERT fails.
Obviously it's trying to insert the repeater form into the Detail table. How do I stop that from happening when the repeater is blank and not filled out? Any help would be appreciated. Thanks. Here's my form:
<?php

public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
TextInput::make('Name')
->required()
->minLength(2)
->maxLength(191),
Toggle::make('IsActive')
->default(true)
->onColor('success')
->offColor('danger'),
]),
Section::make('Details')
->schema([
Repeater::make('Detail')
->schema([
TextInput::make('Name'),
Toggle::make('IsRequired')
->default(false)
->onColor('success')
->offColor('danger')
->label('require'),
])
->label('Detail')
->deleteAction(
fn (Forms\Components\Actions\Action $action) => $action->requiresConfirmation(),
)
->addActionLabel('Add Detail')
->relationship()
->reorderableWithButtons()
->orderColumn('Rank')
->cloneable()
]),
]);
}
<?php

public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
TextInput::make('Name')
->required()
->minLength(2)
->maxLength(191),
Toggle::make('IsActive')
->default(true)
->onColor('success')
->offColor('danger'),
]),
Section::make('Details')
->schema([
Repeater::make('Detail')
->schema([
TextInput::make('Name'),
Toggle::make('IsRequired')
->default(false)
->onColor('success')
->offColor('danger')
->label('require'),
])
->label('Detail')
->deleteAction(
fn (Forms\Components\Actions\Action $action) => $action->requiresConfirmation(),
)
->addActionLabel('Add Detail')
->relationship()
->reorderableWithButtons()
->orderColumn('Rank')
->cloneable()
]),
]);
}
1 Reply
awcodes
awcodes10mo ago
If it’s optional then your database column needs to be nullable.
Want results from more Discord servers?
Add your server