slug is not generated within createOptionForm
slug is not generated within createOptionForm
How do I solve this?
Forms\Components\TextInput::make(name: 'name')
->required()
->maxlength(255)
->live(onBlur: true)
->unique(ignoreRecord: true)
->afterStateUpdated(function(string $operation, $state, Forms\Set $set)
{
if($operation !== 'create') {
return;
}
$set('slug', Str::slug($state));
}),
Forms\Components\TextInput::make(name: 'slug')
->disabled()
->dehydrated()
->required()
->maxlength(255)
->unique(table: Category::class, column: 'slug', ignoreRecord: true),
Forms\Components\TextInput::make(name: 'name')
->required()
->maxlength(255)
->live(onBlur: true)
->unique(ignoreRecord: true)
->afterStateUpdated(function(string $operation, $state, Forms\Set $set)
{
if($operation !== 'create') {
return;
}
$set('slug', Str::slug($state));
}),
Forms\Components\TextInput::make(name: 'slug')
->disabled()
->dehydrated()
->required()
->maxlength(255)
->unique(table: Category::class, column: 'slug', ignoreRecord: true),
5 Replies
Anyone?
Try using:
->live(onBlur: true)
also on the field to be set, that is, slug.
I usually do it that way.
Funny thing is that the exact code is working in the product resource
Did you check the value of
$operation
?The problem is there. I changed !== to === and now it works