Filamentphp v3 Form
Summary
- TextInput - {:.} Masking Rupiah - {:.} hide button by query url tabs - {:.} upload file with random last prefix - {:.} Add button inside form
TextInput
Masking Rupiah
1
2
3
4
Forms\Components\TextInput::make('rupiah')
->mask(RawJs::make('$money($input, \',\', \'.\', 2)'))
->dehydrateStateUsing(fn ($state) => str_replace(['.', ','], ['', '.'], $state))
->afterStateHydrated(fn ($state) => number_format($value, $sep, ',', '.'))
hide button by query url tabs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
->extraAttributes([
'x-init' => "
window.addEventListener(`DOMContentLoaded`, function(event) {
qtab = new URLSearchParams(location.search).get(`tab`);
if(typeof qtab != `undefined`){
if(qtab == `ort-laman-2-tab`){
show = true;
}
}
});
window.addEventListener(`click`, function(){
qtab = new URLSearchParams(location.search).get(`tab`);
show = false;
if(qtab == `ort-laman-2-tab`){
show = true;
}
});
",
'x-data' => "{ show: false }",
'x-show' => "show",
])
upload file with random last prefix
1
2
3
4
5
6
7
Forms\Components\FileUpload::make('lhp_final_dokumen')
->inlineLabel()
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => (string) str(
str($file->getClientOriginalName())->replaceEnd('.' . $file->guessExtension(), '')
)->append('-' . date('Ymdhis') . '.' . $file->guessExtension()),
)
Add button inside form
1
2
3
4
5
6
7
8
9
Forms\Components\TextInput::make('token')
->label(__('Token ')),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('Generate Token')
->action(function (Forms\Get $get, Forms\Set $set) {
$set('token', str()->random(20));
})
])
###