Limiting validation rules

I have a single form with multiple sections. I declare the validation rules for each field via the ->rules() method. I would like to only process the validation rules for the section that the action button was pressed in. I have reasons for using ->rules() instead of Filaments helper methods like ->string().

In the following code, when the personal_action button is pressed, I want to validate
name
but not company_name. Or, when the business_action is pressed, I want to validate company_name but not
name
.

Is there a way to accomplish with Filament?

public function form(Form $form): Form
{
    return $form->schema([
        Section::make('personal')
            ->schema([
                TextInput::make('name')
                    ->rules(['max:20', 'required']),
                Actions::make([
                    Action::make('personal_action')
                        ->action(function (Set $set) {
                            $this->form->getState();

                            doSomethingMagical();
                        }),
                ]),
            ]),
        Section::make('business')
            ->schema([
                TextInput::make('company_name')
                    ->rules(['max:20', 'required']),
                Actions::make([
                    Action::make('business_action')
                        ->action(function (Set $set) {
                            $this->form->getState();

                            doSomethingMagical();
                        }),
                ]),
            ]),
    ]);
}
Was this page helpful?