FilamentF
Filament8mo ago
alan

Unexpected Dehydration of Hidden Fields with statePath

Why are fields that are hidden and located inside a Section with a statePath dehydrated, and how can this be avoided (while still using statePath)? Normally, hidden inputs should be hidden. Or not?

Example:

protected function handleRecordCreation(array $data): Model
{
    Log::info(json_encode($data, JSON_PRETTY_PRINT));
    dd($data);
}

public function form(Form $form): Form
{
    return $form->schema([
        Section::make("Your Information")->schema([
            TextInput::make('name')->label("Your Name (for section)")->default('test')->hidden(),
        ])
        ->columns(2)
        ->statePath('data'),
    ]);
}


=> log:

array:1 [▼
  "data" => array:1 [
    "name" => "test"
  ] // (not correct)
]


without state Path:

protected function handleRecordCreation(array $data): Model
{
    Log::info(json_encode($data, JSON_PRETTY_PRINT));
    dd($data);
}

public function form(Form $form): Form
{
    return $form->schema([
        Section::make("Your Information")->schema([
            TextInput::make('name')->label("Your Name (for section)")->default('test')->hidden(),
        ])
        ->columns(2), 
        //->statePath('data'), statePath removed
    ]);
}


log:

[] // (correct)
Was this page helpful?