F
Filament17mo 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
krekas17mo ago
you also need to add live()
arul
arulOP17mo ago
Yes, but still null no value .. to show in my text input
krekas
krekas17mo ago
Show more code formatted correctly in markdown. Read #✅┊rules how to do that
arul
arulOP17mo ago
This my code
No description
krekas
krekas17mo ago
Ow god 🤦‍♂️ please no screenshots. Read #✅┊rules !
arul
arulOP17mo ago
Sorry
arul
arulOP17mo ago
Gist
help GET $get in filament
help GET $get in filament. GitHub Gist: instantly share code, notes, and snippets.
arul
arulOP17mo ago
My code
Sanchit Patil
Sanchit Patil17mo 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
arulOP17mo ago
Work $set thanks. Buat i wonder how to show $get() . In default().

Did you find this page helpful?