F
Filament2mo ago
BBQfun

How to modify data before validation in simple(modal) resource

beforeValidate() is working on normal resource page, but it didn't work on simple(modal) resource i can't see dd() message after submit the form in the modal
class ManagePosts extends ManageRecords
{
protected function beforeValidate(): void
{
dd('hello');

if (isset($this->data['title']) && is_string($this->data['title'])) {
$this->data['title'] = Str::squish($this->data['title']);
}
}
}
class ManagePosts extends ManageRecords
{
protected function beforeValidate(): void
{
dd('hello');

if (isset($this->data['title']) && is_string($this->data['title'])) {
$this->data['title'] = Str::squish($this->data['title']);
}
}
}
2 Replies
toeknee
toeknee2mo ago
afterStateUpdated would really be the only way to modfiy the data after input.
BBQfun
BBQfunOP2mo ago
I have a resource pages, the beforeValidate() is work perfect
class CreateRole extends CreateRecord
{
protected function beforeValidate(): void
{
if (isset($this->data['role_name']) && is_string($this->data['role_name'])) {
$this->data['role_name'] = Str::squish($this->data['role_name']);
} else {
$this->data['role_name'] = null;
}
}
}

class EditRole extends EditRecord
{
protected function beforeValidate(): void
{
if (isset($this->data['role_name']) && is_string($this->data['role_name'])) {
$this->data['role_name'] = Str::squish($this->data['role_name']);
} else {
$this->data['role_name'] = null;
}
}
}
class CreateRole extends CreateRecord
{
protected function beforeValidate(): void
{
if (isset($this->data['role_name']) && is_string($this->data['role_name'])) {
$this->data['role_name'] = Str::squish($this->data['role_name']);
} else {
$this->data['role_name'] = null;
}
}
}

class EditRole extends EditRecord
{
protected function beforeValidate(): void
{
if (isset($this->data['role_name']) && is_string($this->data['role_name'])) {
$this->data['role_name'] = Str::squish($this->data['role_name']);
} else {
$this->data['role_name'] = null;
}
}
}
so it means in simple(modal) resource, there is no method to modify the data before validation? because there is only one file inside the pages folder
class ManagePosts extends ManageRecords
{

}
class ManagePosts extends ManageRecords
{

}
Thankyou toeknee, so it means when i use modal, afterStateUpdated is the only way to modify state before validation?

Did you find this page helpful?