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