F
Filament15mo ago
daisy21

Changing Label and Visibility based from radio value

Fieldset::make('Kategori Permohonan')
->schema([
Radio::make('kategori')
->label('')
->options([
'Perorangan' => 'Perorangan',
'Lembaga / Organisasi' => 'Lembaga / Organisasi',
])->required()->columnSpan('full')->inline()->default('Perorangan'),
]),

TextInput::make('nomor_identitas')
->label(function (Closure $get){

if(strcmp($get('kategori'),'Perorangan')){
return (string) "NIK/No.Identitas Pribadi";
}
return (string) "NIK/No.Identitas Pimpinan";
})
->required()
->maxLength(255),
TextInput::make('nama_identitas')
->label(function (Closure $get){

if($get('kategori')==='Perorangan'){
return (string) "Nama Lengkap";
}
return (string) "Nama Lembaga / Organisasi";
})
->required()
->maxLength(255),
FileUpload::make('file_identitas')
->required()
->label(function (Closure $get){

if(strcmp($get('kategori'),'Perorangan')){
return (string) "Upload KTP Pribadi";
}
return (string) "Upload KTP Pimpinan";
})
->enableOpen()
->reactive()
->directory('ktp-pemohon')
->disk('private')->columnSpan('full')
->visible(fn (Closure $get) => strcmp($get('kategori'),'Lembaga / Organisasi'))->columnSpan('full'),

Fieldset::make('Kategori Permohonan')
->schema([
Radio::make('kategori')
->label('')
->options([
'Perorangan' => 'Perorangan',
'Lembaga / Organisasi' => 'Lembaga / Organisasi',
])->required()->columnSpan('full')->inline()->default('Perorangan'),
]),

TextInput::make('nomor_identitas')
->label(function (Closure $get){

if(strcmp($get('kategori'),'Perorangan')){
return (string) "NIK/No.Identitas Pribadi";
}
return (string) "NIK/No.Identitas Pimpinan";
})
->required()
->maxLength(255),
TextInput::make('nama_identitas')
->label(function (Closure $get){

if($get('kategori')==='Perorangan'){
return (string) "Nama Lengkap";
}
return (string) "Nama Lembaga / Organisasi";
})
->required()
->maxLength(255),
FileUpload::make('file_identitas')
->required()
->label(function (Closure $get){

if(strcmp($get('kategori'),'Perorangan')){
return (string) "Upload KTP Pribadi";
}
return (string) "Upload KTP Pimpinan";
})
->enableOpen()
->reactive()
->directory('ktp-pemohon')
->disk('private')->columnSpan('full')
->visible(fn (Closure $get) => strcmp($get('kategori'),'Lembaga / Organisasi'))->columnSpan('full'),

tried adding reactive still no luck the label wont change
4 Replies
daisy21
daisy21OP15mo ago
tried adding afterstateupdated on radio button too, same no luck
cheesegrits
cheesegrits15mo ago
Did you add reactive() to the radio? Also, you know that strcmp() returns a falsy value (0) if two strings are the same?
daisy21
daisy21OP15mo ago
i add reactive to all fields i need same no luck yes i just changed to === operator
cheesegrits
cheesegrits15mo ago
OK, past the code you have now. And add php to your code format backticks, makes it easier to read.
Want results from more Discord servers?
Add your server