Computed state in form fields.

Hi, I'd like to have the state totally computed in some form fields. The state would be calculated with a function, and refreshed at each render. Like a Placeholder, but with real fields. Basically doing the same as we can with disabled, or readOnly but with the state. On the table, we can use getStateUsing: Tables\Columns\TextColumn::make('foo')->getStateUsing(fn ($record) => Foo::compute($record)) Setting the state directly using state(fn() => ...) on a TextInput throws an error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization (in the getLivewire function). Is it something easily possible? Could we add a getStateUsing to the input as well? (I can open a PR) Thanks!
2 Replies
Dennis Koch
Dennis Koch5w ago
Could we add a getStateUsing to the input as well? (I can open a PR)
I guess that doesn't exist for a reason. Usually you would use ->afterStateUpdated() on the fields that change
mathieutu
mathieutuOP5w ago
Yep, but it's not handy when you play with a lot of fields. I'm used to modern frontend framework like React, Vue and Svelte, where you can derive your state from other fields easily. The Placeholder component is working well, but it would be great to have that to all components. For a select you can compute the options easily, why not for its state?
Want results from more Discord servers?
Add your server