F
Filament2y ago
arul

how to Get $get value from another text input

I want get value for another textinput. My code TextInput::make('stok')->default(fn(Get $get) => $get('jenis_barang_id')) how to show $get('jenis_barang_id); In my textInput i want to query in default()
10 Replies
krekas
krekas2y ago
you also need to add live()
arul
arulOP2y ago
Yes, but still null no value .. to show in my text input
krekas
krekas2y ago
Show more code formatted correctly in markdown. Read #✅┊rules how to do that
arul
arulOP2y ago
This my code
No description
krekas
krekas2y ago
Ow god 🤦‍♂️ please no screenshots. Read #✅┊rules !
arul
arulOP2y ago
Sorry
arul
arulOP2y ago
Gist
help GET $get in filament
help GET $get in filament. GitHub Gist: instantly share code, notes, and snippets.
arul
arulOP2y ago
My code
Sanchit Patil
Sanchit Patil2y ago
this might help, (not been tested).
Select::make('jenis_barang_id')
->options(StokBarang::where('aktive', 1)->pluck('nama_barang', 'id'))
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function (Forms\Set $set, ?string $state){
$val = DB::table('stok_barangs')
->select(DB::raw('stok_awal + masuk - keluar AS sisa_stok'))
->where('id', $state)->value('sisa_stok');
$set('sisa_stok', $val);
}),

TextInput::make('sisa_stok')->readOnly(),
Select::make('jenis_barang_id')
->options(StokBarang::where('aktive', 1)->pluck('nama_barang', 'id'))
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function (Forms\Set $set, ?string $state){
$val = DB::table('stok_barangs')
->select(DB::raw('stok_awal + masuk - keluar AS sisa_stok'))
->where('id', $state)->value('sisa_stok');
$set('sisa_stok', $val);
}),

TextInput::make('sisa_stok')->readOnly(),
More here: https://filamentphp.com/docs/3.x/forms/advanced#generating-a-slug-from-a-title
arul
arulOP2y ago
Work $set thanks. Buat i wonder how to show $get() . In default().

Did you find this page helpful?