slug is not generated within createOptionForm

slug is not generated within createOptionForm
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),
How do I solve this?
No description
5 Replies
raheel3031
raheel30316d ago
Anyone?
Albert Lens
Albert Lens6d ago
Try using: ->live(onBlur: true) also on the field to be set, that is, slug. I usually do it that way.
raheel3031
raheel30316d ago
Funny thing is that the exact code is working in the product resource
Dennis Koch
Dennis Koch6d ago
Did you check the value of $operation?
raheel3031
raheel30316d ago
The problem is there. I changed !== to === and now it works
Want results from more Discord servers?
Add your server