Validation not working when state change occurs

I am trying to use regex validation with my slug TextInput. The value of this field is also automatically updated based on name. Now the issue is when i change the slug and save, it validates just fine. But if I change the nam, the slug also updates and even if it is all right, I get validation error. I am inclining towards a bug in the core that's causing this. If anyone have faced similar issue and figured a workaround, please help me with this. Thank You
TextInput::make('name')
->live(onBlur: true)
->unique(ignoreRecord: true)
->placeholder('Enter Brand Name')
->maxLength(255)
->afterStateUpdated(function ($get, $set, ?string $state) {
if (!$get('is_slug_changed_manually') && filled($state)) {
$set('slug', str($state)->slug());
}
}),
TextInput::make()
->afterStateUpdated(function ($set) {
$set('is_slug_changed_manually', true);
})
->unique(ignoreRecord: true)
->required()
->regex('/^[a-z0-9]+(-[a-z0-9]+)*$/')
->validationMessages([
'regex' => 'Slug must start/end with a letter/number and may include only lowercase letters, numbers, and hyphens.',
])
->maxLength(255),
TextInput::make('name')
->live(onBlur: true)
->unique(ignoreRecord: true)
->placeholder('Enter Brand Name')
->maxLength(255)
->afterStateUpdated(function ($get, $set, ?string $state) {
if (!$get('is_slug_changed_manually') && filled($state)) {
$set('slug', str($state)->slug());
}
}),
TextInput::make()
->afterStateUpdated(function ($set) {
$set('is_slug_changed_manually', true);
})
->unique(ignoreRecord: true)
->required()
->regex('/^[a-z0-9]+(-[a-z0-9]+)*$/')
->validationMessages([
'regex' => 'Slug must start/end with a letter/number and may include only lowercase letters, numbers, and hyphens.',
])
->maxLength(255),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server