Lazy Mode with Conditional Visibility & Custom AutoSave Behavior

I'm building a Filament form and I want to implement two behaviors for my fields:

  1. Conditional VisibilityI want the TextInput field (answer) to only be visible if the Select field (question) has a value of `1 (Yes)`. If `0 (No)`, it should hide the TextInput.
  2. Per-Field AutoSave (on Submit Only)Each field has an `autoSave()` function that should be triggered only on form submission (or a button click).However, when changing the Select field (to toggle visibility), I want to prevent triggering autoSave on the hidden/shown field. Basically:
✅ autoSave should run on submit

❌ autoSave should not run when Select changes

Here's my current setup:

Select::make('question')
    ->options([
        1 => 'Yes',
        0 => 'No'
    ])
    ->required(),

TextInput::make('answer')
    ->lazy()
    ->required()
    ->dehydrateStateUsing(function ($state) {
        
    })
    ->afterStateUpdated(function (TextInput $component, $state) {
        // currently runs on change – I want to skip this if just toggled
        // $this->autoSave('answer', $state);
    })


My Questions:
How can I conditionally show/hide the TextInput based on the Select value?

How do I suppress autoSave on afterStateUpdated() when visibility is toggled?

Is there a clean way to handle this without triggering unnecessary saves?

Any best practices or suggested patterns are welcome!
Was this page helpful?